JQuery跨域JSON总是导致XHR 200错误
我想使用JQuery JSON跨域查询在我的页面上显示一些数据。 我总是收到XHR 200错误,如果我使用浏览器请求(直接URL)查询数据,我就能够将数据收集为有效的JSON 以下是我正在使用的代码:JQuery跨域JSON总是导致XHR 200错误,json,jquery,cross-domain,jsonp,Json,Jquery,Cross Domain,Jsonp,我想使用JQuery JSON跨域查询在我的页面上显示一些数据。 我总是收到XHR 200错误,如果我使用浏览器请求(直接URL)查询数据,我就能够将数据收集为有效的JSON 以下是我正在使用的代码: $.ajax({ url: 'www.mytestdomain.com/?some=paramters', contentType: 'application/x-www-form-urlencoded; charset=utf-8', type:
$.ajax({
url: 'www.mytestdomain.com/?some=paramters',
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
type: 'POST',
dataType: 'jsonp',
data: {},
success: function (data) {
//some display logic is here,
//which is working fine
//if in same domain using json and not as jsonp
});
},
error: function (xhr, status, thrownError) {
throwServiceError(xhr, status, thrownError);
}
});
注意:我尝试使用回调函数和callback=?在请求URL中,尽管结果保持不变,请建议可行的解决方案。您的服务器从jsonp请求返回什么?服务器是否支持jsonpIt说请求中止-200,以及我们如何知道支持jsonp?
//function to show specific jq error
function throwServiceError(xhr, status, thrownError) {
$("#error-wrapper").empty();
switch (xhr.status) {
case 404:
$("#error-wrapper").append('File not found');
break;
case 500:
$("#error-wrapper").append('Server error');
break;
case 200:
$("#error-wrapper").append(xhr.status + ":- " + thrownError);
break;
case 0:
$("#error-wrapper").append('Request aborted');
break;
default:
$("#error-wrapper").append('Unknown error ' + xhr.status);
break;
}
}