Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getJSON using an IP is not working

my problem is:

When I call json using the following code

var url="http://localhost:9000/json";
$.getJSON(url,
 function(data){
    alert(data['yay']);
    });

It works PERFECT, but, my localhost IP is 10.0.0.145, and when I replace localhost with the IP address, it no longer works

var url="http://10.0.0.145:9000/json";
$.getJSON(url,
 function(data){
    alert(data['yay']);
    });
like image 315
rudighert Avatar asked Aug 29 '12 13:08

rudighert


1 Answers

You are violating the same origin policy. If you control the destination site, you should either consider using a JSONP style of call or enable the cross domain option (crossDomain) on your site and in your AJAX call.

Your browser won't make the call, by default, if you're violating same origin. You'll know that by watching your HTTP traffic using Fiddler, FireBug or Chrome Tools. You won't see your request even executed. If that's the case, then take one of the approaches above.

I hope this helps. Good luck!

like image 194
David Hoerster Avatar answered Sep 21 '22 17:09

David Hoerster