我想从服务器上取一些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用于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();
});
});
有人可以帮我解决问题吗?
答案 0 :(得分:0)
如评论中所述,您在$.ajax
请求中查询的服务器将以JSON格式而不是JSONP返回结果。看看JSON和JSONP Here之间的区别。这是伪代码(PHP)中的一个基本示例,用于检查请求是否实际上是JSONP
$callback = (isset($_GET['callback']) ? $_GET['callback'] : null);
if (isset($callback))
echo $callback . '([JSON HERE])';
else
echo '[JSON HERE]';