只想找到解决方案。我在系统A中,我进行了以下调用
$("#page-form").submit(function(event){
$.ajax({
type: "POST",
url: "https://someOtherUrl/process.php",
data: {
'mobNumber': $("#mobile").val()
}
}).done(function (response) {
alert(response);
});
})
现在,这会调用另一台服务器上的PHP文件。这个PHP文件暂时没有任何功能,我只需要
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
var_dump("1");
但是我收到了跨源请求阻止错误。为什么会发生这种情况?
作为旁注,我无法访问运行系统A的服务器,因此必须在我的PHP文件所在的服务器上完成。
由于
更新
服务器似乎有这个 回复标题
Cache-Control no-cache
Connection Keep-Alive
Content-Type text/html; charset=utf-8
Date Thu, 25 Jun 2015 12:31:50 GMT
Expires Thu, 25 Jun 2015 12:31:50 GMT
Keep-Alive timeout=5, max=99
Pragma no-cache
Server Apache
Transfer-Encoding chunked
Vary Accept-Encoding
x-ua-compatible IE=edge
请求标题
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Connection keep-alive
User-Agent
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0
答案 0 :(得分:0)
在https://someOtherUrl/上的根文件夹中的.htaccess文件中尝试此操作:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>