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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 Matlab打开默认名称带有/的光谱数据
    • ¥50 easyExcel模板 动态单元格合并列
    • ¥15 res.rows如何取值使用
    • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
    • ¥15 CSP算法实现EEG特征提取,哪一步错了?
    • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
    • ¥15 vue3前端取消收藏的不会引用collectId
    • ¥15 delphi7 HMAC_SHA256方式加密
    • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴
    • ¥15 下列c语言代码为何输出了多余的空格