[英]Cross-domain AJAX not working PHP
I have tried to implement a cross-domain AJAX request, based on this answer . 我试图根据这个答案实现跨域AJAX请求。
http://jsfiddle.net/PXSMQ/1/ http://jsfiddle.net/PXSMQ/1/
I have added the following headers: 我添加了以下标题:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
header("Access-Control-Allow-Headers: x-requested-with");
header('Access-Control-Allow-Headers: x-csrf-token');
But I still get this error: 但我仍然得到这个错误:
XMLHttpRequest cannot load http://www.belardi.ro/userTrack/addData.php. Origin http://fiddle.jshell.net is not allowed by Access-Control-Allow-Origin.
The Access Control
headers have to be configured on the server that you're sending your request to. 必须在要向其发送请求的服务器上配置
Access Control
标头。 You can't set them yourself. 你不能自己设置它们。 If the server you're sending your request to is not configured appropriately you won't be able to make these requests.
如果您发送请求的服务器配置不正确,您将无法提出这些请求。
Those headers are not appearing in the response from addData.php
: 那些标题没有出现在
addData.php
的响应中:
david@raston ~ $ curl -i -d 'some=json' http://www.belardi.ro/userTrack/addData.php
HTTP/1.1 200 OK
Date: Wed, 19 Jun 2013 10:12:35 GMT
Server: LiteSpeed
Connection: close
X-Powered-By: PHP/5.2.14
Content-Type: text/html
Content-Length: 16
Vary: User-Agent
Invalid page url~ :
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.