gpt4 book ai didi

javascript - 重新创建 Ajax POST

转载 作者:行者123 更新时间:2023-11-28 19:10:30 25 4
gpt4 key购买 nike

我想重新创建 Ajax POST,我可以通过 Chrome 的调试器达到峰值。

我创建了这样的帖子:

$.ajax({
method: "POST",
url: url,
contentType: "application/json; charset=UTF-8",
data: { "defaults": "default", "culture": "en-US", "skip": 20, "take": 20, "query": "", "filters": [], "fulltext": [], "sorting": { "field": "ModifiedOn", "asc": false } }

})
.done(function (msg) {
alert("Data Saved: " + msg);
});

我收到 500 错误。我检查了一下,我的请求有效负载如下所示:

defaults=default&culture=en-US&skip=20&take=20&query=&sorting%5Bfield%5D=ModifiedOn&sorting%5Basc%5D=false

但是我想要重新创建的源帖子具有不同的请求负载:

{"defaults":"default","culture":"en-US","skip":20,"take":20,"query":"","filters":[],"fulltext":[],"sorting":{"field":"ModifiedOn","asc":false}}

我认为这是导致错误的原因。

如何修改我的请求以使请求负载看起来像后一个?

最佳答案

data: { "defaults": "default", "culture": "en-US", "skip": 20, "take": 20, "query": "", "filters": [], "fulltext": [], "sorting": { "field": "ModifiedOn", "asc": false } }

此行导致错误。您需要像这样对数据进行字符串化:

data: JSON.stringify({ "defaults": "default", "culture": "en-US", "skip": 20, "take": 20, "query": "", "filters": [], "fulltext": [], "sorting": { "field": "ModifiedOn", "asc": false } })  

请阅读有关 jQuery.ajax()-function 的文档。您可以检查所有参数及其类型。

关于javascript - 重新创建 Ajax POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30802896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com