AJAX,子域和200 OK响应AJAX、OK

由网友(思念丶搁浅岁月的变迁)分享简介:一个非假设,但抽象的情况:A non-hypothetical but abstracted situation:我有一个域www.foo.com,从中我在做一个AJAX POST到beta.foo.com。检查XHR对象,我看到了200 OK的响应头,但是没有响应文本 - 我甚至得到回应12B长,这是确切的答复(...

一个非假设,但抽象的情况:

A non-hypothetical but abstracted situation:

我有一个域www.foo.com,从中我在做一个AJAX POST到beta.foo.com。检查XHR对象,我看到了200 OK的响应头,但是没有响应文本 - 我甚至得到回应12B长,这是确切的答复(12个字符的字符串),我很期待 - 但是响应文本为空白。

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.

如果这是一个跨领域的问题,为什么我会收到200 OK,而更好的是 - 为什么我看到的PHP函数火的beta.foo.com方 - 但没有得到响应

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?

推荐答案

您不能做跨子域Ajax调用那么简单。有一种叫做同源策略是prevents你这样做。如果你想解决这问题,你需要使用 JSONP 或内部框架。

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.

安装萤火虫,你会看到一个HTTP 200 code和一个错误:这个错误是SOP的演技

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

阅读全文

相关推荐

最新文章