JQuery JSONP "Uncaught SyntaxError: Unexpected token:"

Here is my AJAX call:

$.ajax({ type: 'GET', url: User.baseURL + 'api/users/briefProfile', dataType: 'jsonp', success:function(data,text,xhqr){ //var data = $.parseJSON(data); console.log(data); }, error: function(jqXHR, textStatus, errorThrown) { console.log("ERROR"); }, complete: function(jqXHR, textStatus) { console.log("complete"); } }); 

Error: Uncaught SyntaxError: Unexpected token :

I get a 200 response in Chrome (last). I get all the content in the response, which is valid JSON. I don’t care that the browser doesn’t parse it correctly, but I would really like to access it in a full callback.

Any idea that a) is causing an error? b) how to get to the returned client side of the content?

+6
source share
4 answers

server needs jsonp support.

and the answer should look like this:

 jsonpcallbackname&&jsonpcallbackname({{"guid":"E5FC2115FF59","lastName":"Smith","JSESSIONID":"HVQN6jITo8aa8KrHV"...}}) 
0
source

Your server (web service) must support JSONP (cross browser support).

0
source

I think you need to add a callback function to your code

 url: User.baseURL + 'api/users/briefProfile?jsoncallback=callbackFunction', function callbackFunction() { // code to execute in success handler } 
-1
source

I had a similar problem and I can fix it with eval . try the following:

  eval("(" + data + ")") 
-3
source

Source: https://habr.com/ru/post/896513/


All Articles