jQuery Ajax简单调用 [英] jQuery Ajax simple call

查看:91
本文介绍了jQuery Ajax简单调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基本的ajax调用.因此,我在测试服务器上托管了以下测试php: http://voicebunny.comeze.com/index.php?numberOfWords=10 该网页是我自己的测试,已经集成到VoiceBunny API http://voicebunny.com/developers 中.

I'm trying a basic ajax call. So I'm hosting the following test php on a test server: http://voicebunny.comeze.com/index.php?numberOfWords=10 This web page is my own test that is already integrated to the VoiceBunny API http://voicebunny.com/developers.

现在,我需要使用jQuery在该其他网页中获取该网页打印的数据. 如您所见,网页回显了一些JSON.如何从另一个网页获取此JSON?

Now I need to get the data printed by that web page in some other web page using jQuery. As you can see the web page echo's some JSON. How can I get this JSON from another web page?

这是我的代码:

 $.ajax({

        'url' : 'http://voicebunny.comeze.com/index.php',
        'type' : 'GET',
        'data' : {
            'numberOfWords' : 10
        },
        'success' : function(data) {              
            alert('Data: '+data);
        },
        'error' : function(request,error)
        {
            alert("Request: "+JSON.stringify(request));
        }
    });

我尝试了许多其他变体,但总是收到错误消息,而从未收到JSON.谢谢

I have tried many other variations but I always get an error and never the JSON. Thank you

推荐答案

请在ajax中设置 dataType config属性,然后再试一次!

please set dataType config property in your ajax call a give it another try!

另一点是,您正在使用ajax调用设置配置属性作为字符串,并且错误地是参考站点

another point is you are using ajax call setup configuration properties as string and it is wrong as reference site

$.ajax({

    url : 'http://voicebunny.comeze.com/index.php',
    type : 'GET',
    data : {
        'numberOfWords' : 10
    },
    dataType:'json',
    success : function(data) {              
        alert('Data: '+data);
    },
    error : function(request,error)
    {
        alert("Request: "+JSON.stringify(request));
    }
});

希望对您有所帮助!

这篇关于jQuery Ajax简单调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆