AJAX,子域和200 OK响应 [英] AJAX, Subdomains and the 200 OK response

查看:109
本文介绍了AJAX,子域和200 OK响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 或<一HREF =htt​​p://ajaxpatterns.org/IFrame_Call相对=nofollow>内部框架。

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.

这篇关于AJAX,子域和200 OK响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆