简体   繁体   中英

error response json: Unexpected token “:”

I have programming a Jquery Mobile application and I use an ajax request (method $.ajax(config)) to get my data. Well when I use tha value "json" in the "dataType" property, I have an error javascript which tell me "Non-Access-Control-Orogin" in the header. And when I use the value "jsonp" in the "dataType" property I have the response from the server but I get an error in the Json of response. "Unexpected token: :". Any advice to resolve this problem?

This is the URL to connect my server: http://rete.mywebsite.com/api3.0?param1=value1&param2=value2

This is my code to get the data in the Json format: (Pardon the uncorrect tab)

$.ajax({ url: MY_URL, dataType: "jsonp", contentType: "application/json", crossDomain: true, success: function(response) { console.log(response); } });

The json how I should get is similar this: { "stazione_1":{ "name": "Brescia", "temperature": "7.5", ... } }

But I get the unexpected token error in the console javascript of the browser (I use Chrome)...

I hope this will been of help...

Either set the CORS headers on the server to Access-Control-Allow-Origin:'*'

OR

Change the JSONP so the eval() call does not break.

If you provide code, we might be better able to help...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM