开发者

AJAX, Subdomains and the 200 OK response

开发者 https://www.devze.com 2022-12-30 03:52 出处:网络
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 O

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消