Ajax post being aborted by firefox (not seen in Chrome or IE)

前端 未结 8 497
再見小時候
再見小時候 2020-12-06 04:37

When using firefox, an ajax post request i have is being reported as aborted in firebug. The ajax post works fine in IE and Chrome. It is not a cross domain request. I tr

相关标签:
8条回答
  • 2020-12-06 05:35

    If you are using 2-way SSL auth on a CORS request, Firefox will abort your jQuery ajax requests by default. This is due to differing implementations of CORS in Firefox and Chrome. You can resolve this issue in your client code by adding withCredentials: true to your XHR instances. In jQuery, you can add this to the ajax call:

    xhrFields: {
      withCredentials: true
    }
    

    Check out these bug reports for more details:

    • Chrome sends TLS client certificates in CORS preflight, in violation of spec requirements
    • TLS handshake fails on CORS requests because no certificate is sent

    I've also noticed that Firefox still absolutely refuses to send credentials on OPTIONS preflight requests, so you will need to configure your server to not require them (which seems crazy to me in a 2-way SSL scenario).

    0 讨论(0)
  • 2020-12-06 05:38

    I also had similar issues and tried some of the ideas described above. I finally fixed "aborted" state by :

    1. adding e.preventDefault(); and return false; to buttons event handlers
    2. adding datatype: "json", contentType: "application/json", to jQuery.ajax method params.

    Thx to everyone for the clues.

    0 讨论(0)
提交回复
热议问题