Front page:
$.ajax({
type:'GET',
url:url,
async:false,
jsonpCallback:'jsonCallback',
contentType:"application/json",
dataType:"jsonp",
success:function(json){
alert(json);
},
error:function(e){
console.log(e.message);
}
});
后台Servlet:
JSONObjectjsonObject=newJSONObject();
jsonObject.put("msg","hello");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control","no-cache");
response.getWriter().write(jsonObject.toString());
response.getWriter().flush();
However, when the foreground accepts the value, it throws “syntax error: missing” through firebug debugging; After searching Baidu for a long time, I didn’t find a reliable method. Many posts said it was URL problem, but I’m sure there was no problem with URL. Later, I switched to Google and found out the root of the problem. Hey… The gap, I still recommend Google
Reference website:
http://stackoverflow.com/questions/20658674/syntaxerror-missing-before-statement-jquery-jsonp
Solution:
Just remove the attribute datatype: “jsonp”. I haven’t checked the specific reason yet. I’m off duty. I’ll continue to get to the bottom tomorrow
$.ajax({
type:'GET',
url:url,
contentType:"application/json",
success:function(json){
alert(json);
},
error:function(e){
console.log(e.message);
}});
Similar Posts:
- Convert to IE9 below $. Ajax to return “no transport” across domains
- When parsing background JSON data with Ajax: unexpected token o in JSON at position 1
- Two solutions to cross origin read blocking (CORB) blocked cross origin response error of Web Service API
- JQuery Ajax crossdomain cannot be used in IE [How to Solve]
- [Solved] Jquery ajax “Uncaught TypeError: Illegal invocation”
- [Solved] JS Ajax uploads an error “uncaught type error: illegal invocation”
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- [Solved] Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse
- The differences between response. Getwriter(). Write() and response. Getwriter(). Print(), as well as pritwriter object and out object
- Uncaught SyntaxError: Unexpected token o