AJAX, Subdomains and the 200 OK response

匆匆过客 提交于 2019-12-23 05:28:06

问题


A non-hypothetical but abstracted situation:

I have a domain www.foo.com, from which I'm making an AJAX POST to beta.foo.com. Examining the XHR object, I see a response header of 200 OK, but no response text - I even get a response 12B long, which is the exact response (a 12-character string) that I'm expecting - but the response text is blank.

If this is a cross-domain issue, why am I getting 200 OK, and better yet - why am I seeing the PHP functions fire on the beta.foo.com side - yet getting no response?


回答1:


You can't do cross subdomains ajax calls that easy. There is something called Same origin policy that prevents you from doing that. If you want sort this issue you need to use JSONP or Iframes.

Install firebug and you will see an http 200 code and an error: that error is SOP acting.




回答2:


You mentioned that you're checking the responseText property. Is it possible your response is in XML format?

If you send an XML request, or the response type is 'text/xml', you will get a value for responseXML. I believe that the responseText property can be blank if it's in XML format.

Random example from google:

http://javascript.about.com/library/blajax08.htm



来源:https://stackoverflow.com/questions/2838668/ajax-subdomains-and-the-200-ok-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!