0

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...

Michele
  • 41
  • 1
  • 4
  • Are you controlling the server? If yes, either setup [CORS](http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) or modify your server code to support JSONP. – Felix Kling Feb 27 '14 at 23:27
  • possible duplicate of [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) – Felix Kling Feb 27 '14 at 23:28
  • What does the JSON look like? Do you actually get anything back? – Vivin Paliath Feb 27 '14 at 23:53

1 Answers1

-1

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...

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
Andrew Templeton
  • 1,656
  • 10
  • 13