Jquery ajax text/html到application/json
我在使用下面的ajax请求时出错Jquery ajax text/html到application/json,json,jquery,Json,Jquery,我在使用下面的ajax请求时出错 $.ajax({ url: "http://webservice.users.com:8000/users", dataType: 'jsonp', beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", "Basic b2d1e77hbi5lcmVu1BhczRVYg"); }, success: function (json)
$.ajax({
url: "http://webservice.users.com:8000/users",
dataType: 'jsonp',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic b2d1e77hbi5lcmVu1BhczRVYg");
},
success: function (json) { console.log(json); },
error: function (httpReq, status, exception) {
console.log(status + " " + exception);
}
});
我的调用是跨域的,结果是text/html(也许jquery无法将结果转换为application/json)
控制台错误:
parsererror错误:未调用JQuery1826287364205345511_1351595013388
错误:“语法错误:意外标记:在chrome浏览器中
Chrome开发者工具服务响应标题:
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:180
Content-Type:text/html
Date:Tue, 30 Oct 2012 10:36:57 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=15, max=100
Pragma:no-cache
Server:Apache/2.2.16 (Debian)
Set-Cookie:active_style=style; expires=Wed, 30-Oct-2013 10:36:57 GMT
Vary:Accept-Encoding,User-Agent
服务器响应主体:
{
"data": {
"islogin": "0"
},
"userdata": {
"login": "0"
},
"rstatus": {
"status": "0",
"errno": "5555",
"mesg": "blablabla"
}
}
您的响应主体中有什么?API是否为jsonp服务?如果是这样,他们是否需要url中的其他参数来定义jsonp输出或回调?许多服务json的API并不在jsonp中提供jsonformat@charlietflweb服务API不支持jsonp格式请尝试将
数据类型:“jsonp”
更改为数据类型:“json”
如果服务不支持jsonp,则必须在服务器上或像YQL这样的第三方上使用代理检索json。即使您得到了响应,但由于跨域策略,浏览器也不会处理它