jquery ajax不使用firefox

时间:2014-01-16 13:05:04

标签: jquery html ajax firefox

我正在尝试向URL发送一个简单的请求(没有CGI参数),并让服务器返回一个复杂的(大约50k字节)对象。一切似乎工作正常,直到回复回来并调用.ajax.error()函数。 XHRs(jqXHR和$ .ajax()的返回值没有给出任何有用的信息,除此之外还有一个错误(见#2)。

我正在使用jQuery 1.9.1和jQuery-UI 1.10.3 抱歉,网址是为了安全起见。 sldn.com不是真正的域名和链接 以下将不起作用(除了对JQ ajax页面的引用)。

到目前为止我尝试过:

  1. 将浏览器指向https://server.sldn.com:9007/bin/feed_status/feed_status.cgi,是的,我收到了ajax值。
  2. 使用Live http标头,验证内容类型是否导致冲突(请参阅下面的#1)
  3. 确保.ajax文档here下的可接受JSON规则。 http://api.jquery.com/jQuery.parseJSON/。标签和值必须是双引号,没有单个反斜杠(它们必须加倍)。这需要工作,如果我以一种可展示的方式进行挖掘,可能会使ajax失效。
  4. 在源服务器和目标服务器上进行DNS查找,以检查这是否真的是本地的。 “Local”要求方案(https),服务器(称为server.sldn.com)和端口匹配。方案和服务器匹配,我不确定端口是如何匹配的。
  5. 尝试将localDomain设置为true,false和default。默认为false并将其设置为true会导致.ajax函数在发送请求之前出错。
  6. 将.cgi生成的代码从Web浏览器中取出并粘贴到test_script()中。获取返回值,eval(),并确保JS对文本感到满意。它是。我可以在firebug中浏览生成的对象。
  7. 在get_feed_status_json_error()内部检查“this”值。它给出的最好的是#2。
  8. 1

    https:server.sldn.com:9007/bin/feed_status/feed_status.cgi
    
    GET /bin/feed_status/feed_status.cgi HTTP/1.1
    Host: server.sldn.com:9007
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
    Accept: application/json, text/javascript, */*; q=0.01
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    DNT: 1
    Referer: https:server.sldn.com:9007/feed_status/feed_status.html
    Origin: https:server.sldn.com:9007
    Connection: keep-alive
    
    HTTP/1.1 200 OK
    Date: Wed, 15 Jan 2014 20:19:09 GMT
    Server: Apache/2.0.52 (Red Hat)
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: application/json
    

    2

    Results passed to get_feed_status_json_error()
    0 Object { readyState=0, status=0, statusText="error", more...}
      readyState    0
      responseText  ""
      status    0
      statusText    "error"
    
    1 "error"
    2 ""
    
    
    this:
    accepts             Object { *="*/*", text="text/plain", html="text/html", more...}
    async               true
    contentType         "application/x-www-form-urlencoded; charset=UTF-8"
    contents            Object { xml=RegExp, html=RegExp, json=RegExp, more...}
    converters          Object { text html=true, * text=String(), text json=function(), more...}
    crossDomain         true
    dataType            "json"
    dataTypes           ["text", "json"]
    flatOptions         Object { url=true, context=true}
    global              true
    hasContent          false
    isLocal             false
    jsonp               "callback"
    processData         true
    responseFields      Object { xml="responseXML", text="responseText"}
    type                "GET"
    url                 "https://server.sldn..._status/feed_status.cgi"
    error               function()
    jsonpCallback       function()
    success             function()
    xhr                 createStandardXHR()
    

    3

    $( document ).ready(function() {
    
      $( "#DatePicker" ).datepicker();
    
      $("#debug_info_checkbox").prop("checked", false);
      $("#debug_info_text").hide();
    
      get_feed_status_json();
    
    });
    
    // This typically runs in the 7-10 second range.
    function get_feed_status_json() {
    
    var x =test_script();
    
    $.ajax({
               type: "GET",
                url: "https://server.sldn.com:9007/bin/feed_status/feed_status.cgi",
           dataType: "json",
            success:  get_feed_status_json_success,
              error:  get_feed_status_json_error,
      });
    
    }
    var get_feed_status_json_success =
    function(data, textStatus, jqXHR) {
      alert("Got data!\\n" + textStatus);
      return data;
    };
    
    var get_feed_status_json_error   =
    function(jqXHR, textStatus, errorThrown) {
      alert("Got error:  " + jqXHR.status);
    };
    
    
    
    function test_script() {
      return '{"feeds":{"Big wad of json here"}';
    }
    

    有什么想法吗?

1 个答案:

答案 0 :(得分:0)

足够简单。当我在浏览器中打开网页时,我只在地址栏中键入“server”而不是“server.sldn.com”,并让默认的DNS后缀找到它。

因此,为了避免使用jquery.ajax时遇到的特定版本的痛苦,请确保您的浏览器具有FQDN,否则它在跨源资源共享(CORS)方面存在问题。您可能希望将您的网站重定向到FQDN或类似的内容。