Requested JSON parse failed in jquery ajax

我在客户端有我的abc.html代码,在另一个域的服务器端有pqr.java servlet。但是当我尝试使用数据类型jsonp的jquery ajax调用时,我得到错误“请求的JSON解析失败”,即使我的服务器cosol显示正确的输出。请帮助,紧急。提前感谢


也许你的头有问题。试试下面的代码

response.setContentType("application/json");

i'had added this line already.My mistake was that i was not appending callback function name to my json response at the server end. By the way thanks. I got the answer.

http://www.ibm.com/developerworks/library/wa-aj-jsonp1/wa-aj-jsonp1-pdf.pdf


Even though the OP found an answer, I would like to share a mistake I was doing. In my server side code I was sending 'text' as content-type. However, in the jquery ajax call (from frontend) I had set dataType: 'json' . This mismatch was causing the error on the website. However, it was working fine on the console. Here is an answer giving more details about contentType and dataType - https://stackoverflow.com/a/18701357/5576491

链接地址: http://www.djcxy.com/p/46146.html

上一篇: Ajax与asp.net aspx返回未定义

下一篇: 在jquery ajax中请求JSON解析失败