jQuery $.ajax(), $.post sending “OPTIONS” as REQUEST_METHOD in Firefox

前端 未结 23 2555
傲寒
傲寒 2020-11-22 14:38

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

The plugin should fetch data from a php script via ajax to add options to a

相关标签:
23条回答
  • 2020-11-22 15:33

    I had same problem with sending requests to google maps, and solution is quite simple with jQuery 1.5 - for dataType use dataType: "jsonp"

    0 讨论(0)
  • 2020-11-22 15:33

    I have posted a clear example of how to solve this if control the server code of the domain you are POSTing to. This answer is touched on in this thread, but this more clearly explains it IMO.

    How do I send a cross-domain POST request via JavaScript?

    0 讨论(0)
  • 2020-11-22 15:34

    You need to do some work on server side. I see you are using PHP on server side, but solution for .NET web application is here: Cannot set content-type to 'application/json' in jQuery.ajax

    Do the same in PHP script and it will work. Simply: At first request browser is asking server if is allowed to send such data with such type and second request is the proper/allowed.

    0 讨论(0)
  • 2020-11-22 15:36

    I was looking through source 1.3.2, when using JSONP, the request is made by building a SCRIPT element dynamically, which gets past the browsers Same-domain policy. Naturally, you can't make a POST request using a SCRIPT element, the browser would fetch the result using GET.

    As you are requesting a JSONP call, the SCRIPT element is not generated, because it only does this when the Type of AJAX call is set to GET.

    http://dev.jquery.com/ticket/4690

    0 讨论(0)
  • 2020-11-22 15:38

    Can you try this without

    contentType:application/x-www-form-urlencoded

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