请求的资源上不存在“Access-Control-Allow-Origin”标头。但是当我检查标题时,它被设置为

时间:2017-05-11 15:44:04

标签: php ajax cors

尝试使用AJAX POST到我的脚本时出现以下错误。

XMLHttpRequest cannot load http://nasseira.epizy.com/domPath.php. No 'Access-Control-Allow-Origin' header is present on the requested resource.

AJAX致电:

jQuery.ajax({
  type: "POST",
  url : "http://nasseira.epizy.com/domPath.php",
  data: {json: JSON.stringify(allMyPath)},
  success: function (data) {
     console.log(data);
  },
  error: function(){
     console.log("Error");
  }
});

PHP脚本:

<?php

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size,
  X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");

  return print "ok";
 ?>

然而,当我检查标题时,它似乎设置正确: http://i.imgur.com/rRwBRmU.png

我做错了什么?

0 个答案:

没有答案