0

Running on Chrome I get this error message:

Uncaught SyntaxError: Unexpected token

This is the part of my code which is responsible for the request:

function wetter() {

  $.ajax({
    'Accept': 'application/json',
    type: 'GET',
    url: '[here comes the url',
    dataType: 'jsonp',
    success: function (data) {
      //content
    }
  });
};
GileBrt
  • 1,830
  • 3
  • 20
  • 28
Daria Duda
  • 33
  • 4

2 Answers2

2

You are trying to make a jsonp request to a script that sends json, similar to this. You cant just drop a p after the json and expect it to work.

Community
  • 1
  • 1
Musa
  • 96,336
  • 17
  • 118
  • 137
  • @DariaDuda that's suppose to happen, read up on [Same Origin Policy](http://en.wikipedia.org/wiki/Same_origin_policy) and [Cross-Origin Resource Sharing](http://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing) – Musa Sep 14 '12 at 19:44
  • @DariaDuda the only way this will work is if you use a browser that doesn't enforce same origin policy or you use a serverside proxy – Musa Sep 14 '12 at 20:00
  • But my project requirement is to use a webkit browser, so chrome or safari :( – Daria Duda Sep 14 '12 at 20:07
1

The datatype it's receiving is probably not what it expects. You may be returning a JSON object while the expected result is JSON with padding (JSONP). You can either try returning JSONP type data or change the datatype in your code above to JSON.

Chrysalis
  • 4,130
  • 2
  • 21
  • 23
  • I have changed my function: $.getJSON('http://api.wetter.com/forecast/weather/city/DE0001516/project/fakultaetvierboard/cs/4e7d520eea090e2bb8a8a8c5fc981b12/output/json?callback=?' but it still doesn't work – Daria Duda Sep 14 '12 at 19:58