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

    报告相同问题?

    悬赏问题

    • ¥20 关于#qt#的问题:Qt代码的移植问题
    • ¥50 求图像处理的matlab方案
    • ¥50 winform中使用edge的Kiosk模式
    • ¥15 关于#python#的问题:功能监听网页
    • ¥15 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化