weixin_33713503 2016-12-16 08:29 采纳率: 0%
浏览 59

$ .ajax POST方法不允许

The following code works perfectly fine:

function callWebhookAndShowCart(element) {
    $.ajaxSetup({ 
        xhrFields: { 
            withCredentials: true 
        } 
    });
    var webHook = $(element).attr('webHook');
    var webParams = $(element).attr('webParams');

    if (webHook) {
        $.ajax({
            url: webHook,
            data: webParams,
            dataType: 'json',
            crossDomain: true,
            success: function(cart) {
                getCartRendering(cart);
            },
            error: function() {
                console.log('error');
            }
        });
    }
}

However the following does not work and returns method not allowed:

function callWebhookAndShowCart(element) {
    $.ajaxSetup({ 
        xhrFields: { 
            withCredentials: true 
        } 
    });
    var webHook = $(element).attr('webHook');
    var webParams = $(element).attr('webParams');

    if (webHook) {
        $.ajax({
            type: "POST",
            url: webHook,
            data: webParams,
            dataType: 'json',
            crossDomain: true,
            success: function(cart) {
                getCartRendering(cart);
            },
            error: function() {
                console.log('error');
            }
        });
    }
}

The only change is converting from GET to POST. The server configuration as evident from the response header is:

Response Header
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:x-requested-with, Content-Type, X-PINGOTHER, x-requested-by, Content-length, Connection
Access-Control-Allow-Methods:POST, GET, HEAD, OPTIONS, PUT, DELETE
Access-Control-Allow-Origin:http://localhost:8080
Access-Control-Max-Age:3600
Content-Encoding:gzip
Content-Type:text/html;charset=utf-8
Date:Thu, 15 Dec 2016 08:39:03 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Vary:Accept-Encoding

Please help as I am not sure what needs to be changed for the server configuration for this to work.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
    • ¥15 请教SGeMs软件的使用
    • ¥15 关于#stm32#的问题,请各位专家解答!(语言-c语言)
    • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?
    • ¥50 深度学习运行代码直接中断
    • ¥15 关于#单片机#的问题,请各位专家解答!
    • ¥20 需要完整的共散射点成像代码
    • ¥15 编写vba代码实现数据录入工作
    • ¥15 做过TCL海信电视小米电视相关影视会员软件私我
    • ¥15 Mapreduce是正常的,在运行其他jar包时并没有任何问题,只是在做LogCount.jar 时出的问题。如图所示