我有一个返回 json 的简单宁静服务。我想进行 ajax 调用以获取所需的数据。当我尝试使用 firefox 的 RestClient 时没有问题。服务返回 json,我可以在 rest 客户端上看到 json。但是当我使用 ajax 调用时它失败了。控制台显示200 OK
,但错误函数在调用后执行。我搜索了这个,通常他们说这是一个跨域问题,但我没有解决这个问题。
这是错误函数的失败信息{"readyState":0,"responseText":"","status":0,"statusText":"error"}
AJAX 调用
$.ajax({
type:"GET",
url: "http://localhost:8080/myController/getInfo",
dataType:"json",
success: function(data){
alert(JSON.stringify(data));
},
error: function(msg){
alert("ERROR! \n" + JSON.stringify(msg));
}
});
Firefox 的控制台消息
Content-Type application/json
Date Mon, 18 Feb 2013 11:51:41 GMT
Server Apache-Coyote/1.1
Transfer-Encoding chunked
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3
Host localhost:8080
Origin null
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0
调用返回的数据:
{ "date": "1 hour ago", "photoUrl": "img/movie_detail/celal.jpg", "rating": "three", "title": "Celal ile Ceren" }