Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery.AJAX fails even though firefox says code 200

I cannot get the jQuery to return a success even though the URL which it generates works. The code is as follows:

    var baseURL = "http://api.rottentomatoes.com/api/public/v1.0.json";
    var apiKey = "myAPIKEy";

    $.ajax
    ({
        type: "GET",
        url: baseURL,
        data: { apikey: apiKey },
        success:function()
        {
            alert('here');
        },
        complete:function(data)
        {
            return data;
        }
    });

It does not hit success (I took out failed but it goes into failed). I am not sure why this is failing given I copy paste the generated URL and it works and spits back a response. Please let me know what other information I can provide. I am sorry for being a bit vague. Any help is greatly appreciated!!!

like image 214
Serguei Fedorov Avatar asked Nov 14 '12 01:11

Serguei Fedorov


People also ask

Why is ajax success not working?

ajax post method. The reason was my response was not in the JSON format so there was no need for the dataType: 'json' line in the submit method. In my case, the returned response was in text format that's why it was not going to success event. Solution: Remove dataType: 'json' line.

What causes ajax fail?

Many pages send AJAX requests to a server. Because this relies on the cooperation of the server and the network between the client and the server, you can expect these AJAX errors: Your JavaScript program receives an error response instead of data; Your program has to wait too long for the response.


1 Answers

This will work, for cross domain

var baseURL = "http://api.rottentomatoes.com/api/public/v1.0.json";
var apiKey = "myAPIKEy";

$.getJSON (baseURL + "?callback=?", { apikey: apiKey }, function(data){
        return data;
});
like image 179
James Avatar answered Oct 18 '22 10:10

James