0

I have a ajax call, but is failing everytime with error:"", status:0, but the StatusCode is 200OK. Any help will be appreciated with an working example as im new to ajax.

    $.ajax({
    type: 'GET',
    url: "http://www.myapifilms.com/imdb/inTheaters",
    cache: false,
    crossDomain: true,
    cache: false,
    timeout: 10000000,
    success: function(data) {
        MoviesData = data;
    },
    error: function(jqXHR, textStatus, errorThrown) {
        alert("Ajax error");
    }
});
Nikki
  • 137
  • 2
  • 3
  • 17
  • please try to display returned data as `alert(data);`. What do you get? –  Aug 05 '15 at 12:39
  • 1
    JavaScript cannot make requests to third party domains due to the [Same Origin Policy](http://en.wikipedia.org/wiki/Same-origin_policy). It appears this domain supports JSONP, so you need to use that instead. – Rory McCrossan Aug 05 '15 at 12:42
  • What does the JavaScript console say? What does the `errorThrowm` variable in your error handler say? – Quentin Aug 05 '15 at 12:44
  • i added 2 more parameters to the ajax call contentType: "jsonp", dataType : "jsonp", Now, response is there but trows an error as parseError – Nikki Aug 05 '15 at 12:45

1 Answers1

0

This is most likely due to the target cross-domain server denying your request. If you control the target server, you can add a Access-Control-Allow-Origin tag to the .htaccess file to enable cross domain requests, but otherwise, I would recommend looking for some other method (instead of ajax) of extracting the data you want from the target server/website.

bwright
  • 347
  • 1
  • 15