我正在使用 jQuery 和 Node.js + Express API 制作一个供本地使用的项目。 当我使用 Postman“下订单”时没有问题:
当我这样做时,在我看来,与 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 中用作数据的相同:
任何帮助将不胜感激!
答案 0 :(得分:0)
我必须进行这些调整,现在它起作用了:
type: "post",
url: "http://localhost:3001/roomorder",
data: JSON.stringify ({roomOrderLines: global_orderSummary}),
dataType: "json",
contentType: "application/json",