Why I can't get the result when I using localhost?
My computer ip 开发者_运维技巧is 192.168.11.3, and I do my coding, and I send getJSON request to localhost, the getJSON path is something like this:
http://localhost:8080/requestJSON.php
it works fine when I go to the path:
http://localhost:8080/myApplication.php
But when I changed it to 192.168.11.3, like this :
http://192.168.11.3:8080/myApplication.php
I use the same code, the getJSON still request the JSON in
http://localhost:8080/requestJSON.php
But I can't get what I want. I use this two links in my same computer, it should be the same, when I access localhost, and 192.168.11.3. What happens? thank you.
I suppose one possibility is that your browser is enforcing the same origin policy before trying to resolve the address. Try changing the requestJSON.php
URL to match the address of the URL you're requesting and see if that works.
You probably need to request the JSON from the same host as the page from which you're requesting it. So for instance http://192.168.11.3:8080/myApplication.php
needs to request it from http://192.168.11.3:8080/requestJSON.php
. The easiest way to do this is to use a relative URL in the request.
精彩评论