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!!!
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.
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.
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;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With