Ajax jsonp request. Error: jQuery was not called
Ajax jsonp request. Error: jQuery was not called
我想从服务器获取一些 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 移动设备上使用 jQuery 1.11.1
这是我的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 格式而不是 JSONP 格式返回结果。看看JSON和JSONPHere的区别。这是伪代码 (PHP) 中的一个基本示例,用于检查请求是否实际上是 JSONP
$callback = (isset($_GET['callback']) ? $_GET['callback'] : null);
if (isset($callback))
echo $callback . '([JSON HERE])';
else
echo '[JSON HERE]';
我想从服务器获取一些 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 移动设备上使用 jQuery 1.11.1 这是我的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 格式而不是 JSONP 格式返回结果。看看JSON和JSONPHere的区别。这是伪代码 (PHP) 中的一个基本示例,用于检查请求是否实际上是 JSONP
$callback = (isset($_GET['callback']) ? $_GET['callback'] : null);
if (isset($callback))
echo $callback . '([JSON HERE])';
else
echo '[JSON HERE]';