4

I want to consume a webService which I get JSON Data from

    $.ajax({
    type: 'GET',
    contentType: 'application/json',
    dataType: 'JSON-P',
    //the url shows the correct JSON Data when I copy the URL in my browser
    url: 'http://url.com',
    success: function(data){
        console.log(data);
        alert(data);
    },
       error: function(xhr, testStatus, error){console.log("Error occured: "+error+" "+xhr+" "+testStatus)}
})

In Firefox, It calls back with the error function, but I dont know what the problem is, it would be great to know the error message but my approach doesnt work. thanks in advance

edit: In Chrome I get the following error:

Origin null is not allowed by Access-Control-Allow-Origin.

edit: It´s solved, the problem was indeed that json doesnt work cross site, and the data was not "jsonp-conform" (it had to set a function(json data...))arround the json data. This could be done by changing the url at the end "_&jsonp=successCallback. Sorry for bothering you

最白目
  • 3,505
  • 6
  • 59
  • 114

2 Answers2

1

I think there was a JSON object syntax error. Check your JSON object syntax error with jsonlint.com.

Jeromy French
  • 11,812
  • 19
  • 76
  • 129
anil shah
  • 3,079
  • 2
  • 12
  • 4
0

Are you getting this error locally?

Try it on a server and if it doesn't work: XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin

Community
  • 1
  • 1
Thomas
  • 8,426
  • 1
  • 25
  • 49