如果您使用jQuery进行ajax请求,它将不会发送标头X-Requested-With(HTTP_X_REQUESTED_WITH)=
XMLHttpRequest,因为它是跨域的。但是有两种方法可以解决此问题并发送标头:
选项1)在ajax调用中手动设置标头:
$.ajax({ url: "http://your-url...", headers: {'X-Requested-With': 'XMLHttpRequest'}});选项2)告诉jQuery不要使用跨域默认值,因此它将X-Requested-With标头保留在ajax请求中:
$.ajax({ url: "http://your-url...", crossDomain: false});但是,服务器必须允许这些标头,然后服务器需要打印这些标头:
print "Access-Control-Allow-Origin: *n";print "Access-Control-Allow-Headers: X-Requested-With, Content-Typen";
上面的第一行将避免错误 “ Access-Control-Allow-Origin不允许起源”。
第二行将避免错误 “ Access-Control-Allow-Headers不允许使用请求标头字段X-Requested-With”。



