javascript - Difference between localhost and IP address in Ajax request sending -


i have strange problem native ajax request invoking.

i creating ajax object , sending request follows:

var xmlhttpobj = new xmlhttprequest(); 

....

xmlhttpobj.open("get","http://192.168.16.254:8080/ajax/demoexample.html",true); xmlhttpobj.send(); 

when access servlet url http://localhost:8080/ajax..., not able response in client side. can see response in server side.

pretty similar way invoked request

xmlhttpobj.open("get","http://localhost:8080/ajax/demoexample.html",true); 

and url http://192.168.16.254:8080/ajax..., not able see response in client side.

i know best way fix problem.

i can invoke request

xmlhttpobj.open("get","../ajax/demoexample.html",true); xmlhttpobj.send(); 

then don't have problem either localhost or ip address.

but still think why difference between localhost , ip address in ajax requesting.

it's more of security feature problem :

the same origin policy prevents document or script loaded 1 origin getting or setting properties of document origin.

localhost , 192.168.16.254 considered different origins. same goes 2 hostnames point same address (and will) point different site/application on same server. afaik way around use iframe content or jsonp json. although in case relative urls way go.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -