AJAX调用跨域问题 [英] AJAX call cross domain issue
问题描述
我想使用Ajax调用,这是我问的 previous问题。它应该不回应任何东西。但每当我把这种阿贾克斯功能,火狐(萤火虫)是显示200确定为红色。这必须是一个跨域的问题。试了太多的东西,但至今没有运气。这里是code:
I am trying to login to my wordpress site using ajax call, which i asked in previous question. It should not respond anything back. But whenever i call this ajax function, Firefox(firebug) is showing 200 OK in red. This must be a cross domain issue. Tried too many things but no luck so far. Here is the code:
$.ajax({
type: "POST",
url: "http://path-to-wordpress/wp-login.php",
data:myData
success: function(data){
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
任何建议将AP preciated。
Any suggestion will be appreciated.
推荐答案
我假设你的JS code是在 abc.com
和你的话preSS网站是 dev.abc.com
。
I assume your JS code is on abc.com
and your wordpress site is dev.abc.com
.
要解决跨域问题,只需添加以下code到的.htaccess
文件到你的话preSS网站(开发.abc.com
)
To fix cross domain issue, just add the following code to .htaccess
file to your wordpress site (dev.abc.com
)
SetEnvIf Origin "^http(s)?://(.+\.)?(abc\.com)$" origin_is=$0
Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is
只需更换(ABC \ .COM)
有一个适当的站点名称。对于例如:(谷歌\ .COM)
或(雅虎\ .COM)
Just replace (abc\.com)
with a proper site name. For eg: (google\.com)
or (yahoo\.com)
这篇关于AJAX调用跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!