jQuery$.ajax(),$.post在Firefox中发送“选项”作为请求_方法我认为一个相对简单的jQuery插件有问题.。插件应该通过ajax从php脚本中获取数据,以将选项添加到<select>..Ajax请求非常通用:$.ajax({
url: o.url,
type: 'post',
contentType: "application/x-www-form-urlencoded",
data: '{"method":"getStates", "program":"EXPLORE"}',
success: function (data, status) {
console.log("Success!!");
console.log(data);
console.log(status);
},
error: function (xhr, desc, err) {
console.log(xhr);
console.log("Desc: " + desc + "\nErr:" + err);
}});这在Safari中似乎很好。在Firefox 3.5中,REQUEST_TYPE服务器上总是“选项”,$_POST数据不会出现。Apache将请求记录为“选项”类型:::1 - - [08/Jul/2009:11:43:27 -0500] "OPTIONS sitecodes.php HTTP/1.1" 200 46为什么这个Ajax调用可以在Safari中工作,而在Firefox中却不能工作,以及如何为Firefox修复它?Response Headers
Date: Wed, 08 Jul 2009 21:22:17 GMT
Server:Apache/2.0.59 (Unix) PHP/5.2.6 DAV/2
X-Powered-By: PHP/5.2.6
Content-Length 46
Keep-Alive timeout=15, max=100
Connection Keep-Alive
Content-Type text/html
Request Headers
Host orderform:8888
User-Agent Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1) Gecko/20090624 Firefox/3.5
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Origin http://ux.inetu.act.org
Access-Control-Request-Method POST
Access-Control-Request-Headers x-requested-with下面是Firebug输出的图片:
3 回答
波斯汪
TA贡献1811条经验 获得超4个赞
def send_data(request): if request.method == "OPTIONS": response = HttpResponse() response['Access-Control-Allow-Origin'] = '*' response['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS' response['Access-Control-Max-Age'] = 1000 # note that '*' is not valid for Access-Control-Allow-Headers response['Access-Control-Allow-Headers'] = 'origin, x-csrftoken, content-type, accept' return response if request.method == "POST": # ...
添加回答
举报
0/150
提交
取消