Difference between localhost and IP address in Ajax request sending

前端 未结 1 1401
栀梦
栀梦 2021-01-15 11:40

I have a strange problem with native Ajax request invoking.

I am creating the Ajax object and sending the request like follows:

var xmlHttpObj = new          


        
1条回答
  •  囚心锁ツ
    2021-01-15 11:50

    It's more of a security feature than a problem :

    The same origin policy prevents a document or script loaded from one origin from getting or setting properties of a document from another origin.

    localhost and 192.168.16.254 are considered different origins. The same goes for two hostnames that point to the same address as they could (and probably will) point to a different site/application on the same server. AFAIK the only way around this is to use iframe for content or JSONP for json. Although in your case relative URLs is the way to go.

    0 讨论(0)
提交回复
热议问题