本文介绍了jQuery的$。阿贾克斯(),$。员额发送"方式];作为REQUEST_METHOD在Firefox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么我还以为是个麻烦一个相对简单的jQuery插件...

Having trouble with what I thought was a relatively simple jQuery plugin...

插件应通过AJAX获取数据从一个PHP脚本选项添加到<选择> 。 AJAX请求是pretty的通用的:

The plugin should fetch data from a php script via ajax to add options to a <select>. The ajax request is pretty generic:

$.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日志请求类型选项:

This seems to work fine in Safari. In Firefox 3.5, the REQUEST_TYPE on the server is always 'OPTIONS', and the $_POST data does not appear. Apache logs the request as type 'OPTIONS':

::1 - - [08/Jul/2009:11:43:27 -0500] "OPTIONS sitecodes.php HTTP/1.1" 200 46

为什么会在Safari这个Ajax调用的工作,而不是Firefox和如何解决它的Firefox?

Why would this ajax call work in Safari, but not Firefox, and how do I fix it for 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

下面是萤火虫输出的画面:

Here is a picture of the Firebug output:

推荐答案

原因错误是同源策略。它不仅可以让你做XMLHTT prequests以自己的域名。看看你是否可以使用 JSONP 的回调,而不是:

The reason for the error is the same origin policy. It only allows you to do XMLHTTPRequests to your own domain. See if you can use a JSONP callback instead:

$.getJSON( 'http://<url>/api.php?callback=?', function ( data ) { alert ( data ); } );

这篇关于jQuery的$。阿贾克斯(),$。员额发送&QUOT;方式];作为REQUEST_METHOD在Firefox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 18:55