Does the jQuery ajax call support PATCH?

后端 未结 2 808
梦毁少年i
梦毁少年i 2020-12-02 22:49

When I send this ajax rquest:

$.ajax({
            headers : {
                \'Accept\' : \'application/json\',
                \'Content-Type\' : \'appli         


        
相关标签:
2条回答
  • 2020-12-02 23:17

    Could it be your browser doesn't support the PATCH method?

    Taken from jQuery AJAX API documentation:

    The type of request to make ("POST" or "GET"), default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

    0 讨论(0)
  • 2020-12-02 23:33

    The $.ajax method does support HTTP PATCH.

    The problem you are seeing is that the ajax method looks for PATCH in the Access-Control-Allow-Methods response header of the options preflight check. Either this header is missing from your response, or the PATCH method was not included in the value of this header. In either case, the problem is in the server, not in your client-side code.

    Here's an example using Java:

    response.addHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, PUT, DELETE");
    
    0 讨论(0)
提交回复
热议问题