简体   繁体   English

Ajax jsonp请求。 错误:未调用jQuery

[英]Ajax jsonp request. Error: jQuery was not called

I want to take some json from server but I have Error: 我想从服务器上获取一些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)

I use jQuery 1.11.1 for jQuery mobile It's my js code: 我将jQuery 1.11.1用于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();
    });
});

Can someone help with my problem? 有人可以解决我的问题吗?

As mentioned in a comment, the server you are querying in your $.ajax request is returning the result in JSON format instead of JSONP. 如评论中所述,您在$.ajax请求中查询的服务器以JSON格式而不是JSONP返回结果。 Take a look at the difference between JSON and JSONP Here . 看一下JSON和JSONP Here的区别。 Here is a basic example in pseudocode (PHP) to check if the request is in fact JSONP 这是伪代码(PHP)中的一个基本示例,用于检查请求是否实际上是JSONP

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM