Ajax jsonp request.错误:未调用 jQuery



我想从服务器获取一些json,但我有错误:

Error: jQuery111106328444090202681_1494341431062 was not called
at Function.error (file:///C:/Users/adm/Documents/temp/WP/wp/www/jquery/jquery-1.11.1.min.js:2:1809)
at h.jsonp.b.dataTypes.(anonymous function).b.converters.script json (file:///C:/Users/adm/Documents/temp/WP/wp/www/jquery/jquery-1.11.1.min.js:4:27648)
at Pc (file:///C:/Users/adm/Documents/temp/WP/wp/www/jquery/jquery-1.11.1.min.js:4:18120)
at x (file:///C:/Users/adm/Documents/temp/WP/wp/www/jquery/jquery-1.11.1.min.js:4:21525)
at HTMLScriptElement.b.onload.b.onreadystatechange (file:///C:/Users/adm/Documents/temp/WP/wp/www/jquery/jquery-1.11.1.min.js:4:26934)

我使用 jQuery 1.11.1 for jQuery mobile这是我的js代码:

function myRequest() {
    $.ajax({
        url: "http://dev.agro.ws/result.json",
        dataType: 'jsonp',
        crossDomain: true,
        error: function(xhr, ajaxOptions, thrownError) {
            console.log(xhr.status);
            console.log(thrownError);
        },
        success: function(data) {
            console.log(data);
        }
    });
}
$(document).on("pageinit", "#main", function() {
    $('#btnDownload').click(function(event) {
        myRequest();
    });
});

有人可以帮助解决我的问题吗?

如注释中所述,您在$.ajax请求中查询的服务器以 JSON 格式而不是 JSON 格式返回结果。在这里看看JSON和JSONP之间的区别。下面是伪代码(PHP(中的基本示例,用于检查请求是否实际上是JSONP

$callback = (isset($_GET['callback']) ? $_GET['callback'] : null);
if (isset($callback))
    echo $callback . '([JSON HERE])';
else
    echo '[JSON HERE]';

最新更新