There are several questions on Stack Overflow saying cross domain AJAX request etc will not work because of security reasons. Some questions like this explain this. (Please let me know if I am wrong.)
This is working perfectly fine:
$(document).ready(function() {
$.getJSON("http://search.twitter.com/search.json?q=test&callback=?", function(data) {
alert("test alert outside loop");
$.each(data.results, function() {
alert("test alert inside loop");
});
});
});
But just replacing the URL with my application won't work. In that case response code is 200
, but there's no response data. There is an hit on my application; I can see that in console.
$(document).ready(function() {
$.getJSON("http://192.168.1.2:3000/cities.json?callback=?", function(data) {
alert("test alert outside loop");
$.each(data.results, function() {
alert("test alert inside loop");
});
});
});
I am developing a very simple mobile app using PhoneGap so I need to make this call using JavaScript. But the main thing that's confusing me is why the Twitter call is working, but the call to my app isn't. I've also tried to remove the protect_from_forgery
call in my application controller in my Rails app, but i don't think that matters.
EDIT
i have deployed the app on http://deals.textadda.com/cities.json now check it... Its not working..
U can try it. these two links http://jsfiddle.net/2arbY/ http://jsfiddle.net/fHxf9/