【发布时间】:2014-02-24 15:25:44
【问题描述】:
我用谷歌搜索了很多,没有找到适合我需要的东西。我发现了这些类似的线程here、here 和here,但它们并没有解决我的问题,或者我没有正确理解这一点。我还阅读了几次jersey documentation。
我正在使用 jersey 2.5.1 开发服务器端应用程序,并使用 HTML/CSS/JavaScript 开发客户端应用程序。所以这个效果很好,但不是我绊倒了。 我使用 Media-Moxy 作为我的 Java2Json 映射器。
@GET
@JSONP
@Path("search")
@Produces({MediaType.APPLICATION_JSON, "application/javascript"})
public String findByTagsAndBoundingBox(@QueryParam("topLeftLat") Double topLat...) {
// do some work
return json.toString();
}
如果我现在在命令行上执行 curl(请参阅接受标头作为球衣文档的请求)
curl -X GET -H "Accept: application/javascript" "http://localhost:8181/xxxxx/xxxx/search?topLeftLat=59.93704238758132&topLeftLon=10.68643569946289&bottomRightLat=59.890573111743336&bottomRightLon=10.806941986083984&tag=Restaurant&callback=?"
Jersey 确实按预期交付了内容(在 JSONP 中):
callback([{"id":3134,"lon" .... }])
但是如果我像这样用 jquery 调用它:
$.getJSON("http://localhost:8181/xxxx/yyyy/search?" + query + "&callback=?", function() {
console.log( "success" );
})
我总是得到错误
parsererror, Error: jQuery110207164248435292393_1391195897558 was not called
我可以看到浏览器中的响应包含正确的 json,并且我得到了 200 返回码。但是由于某种原因,jQuery 说有问题。
感谢您的帮助, 丹尼尔
【问题讨论】:
标签: jquery ajax json jsonp jersey-2.0