Ajax Post 请求返回内部错误 500?

时间:2021-07-21 19:22:24

标签: javascript jquery ajax post

我正在使用 jQuery 和 Node.js + Express API 制作一个供本地使用的项目。 当我使用 Postman“下订单”时没有问题:

enter image description here

当我这样做时,在我看来,与 jQuery 一样,我收到内部服务器错误 500:

$.ajax({
        type: "post",
        url: "http://localhost:3001/roomorder",
        data: {
            roomOrderLines: global_orderSummary,
        },
        dataType: "json",

        success: (placeOrderResult) => {

            $('#appContent').html(`success!`);
        },

        error: (xhr, ajaxOptions, thrownError) => {
            global_setError("An error occurred. / "+xhr.status+" / "+thrownError);
        }
    });

global_orderSummary 在我使用 console.log 时看起来像这样,看起来与我在 Postman 中用作数据的相同:

enter image description here

任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

我必须进行这些调整,现在它起作用了:

type: "post",
url: "http://localhost:3001/roomorder",
data: JSON.stringify ({roomOrderLines: global_orderSummary}),
dataType: "json",
contentType: "application/json",