gpt4 book ai didi

javascript - 连接到服务器 AJAX 调用时出错

转载 作者:行者123 更新时间:2023-12-03 01:39:04 25 4
gpt4 key购买 nike

我下面有这段代码,我正在尝试将数据发送到服务器,但我必须连接到它的唯一文档是发送到服务器的示例数据,它看起来像这样 {“method”:“fruit-post”,“data”:{“red-fruits”:["Apple","Cherry","Tomato"],“green-fruits”:["Grapes","Watermelon"],“yellow-fruits”:["Lemon","Pear"],“purple-fruits”:[]}}我在下面的代码中做错了什么吗,因为我不断收到错误 405 和 Response for preflight has invalid HTTP status code 405.任何帮助将不胜感激

var fruitData = {};

var key = "red-fruits";
fruitData[key] = red;

var key2 = "green-fruits";
fruitData[key2] = green;

var key3 = "yellow-fruits";
fruitData[key3] = yellow;

var key4 = "purple-fruits";
fruitData[key4] = purple;

var fruitString = JSON.stringify(fruitString);

$.ajax({
method: "fruit-post",
type: "POST",
url: "LINK",
data: {
"data": fruitString
},
cache: false,
success: function(data) {
}

最佳答案

您的ajax请求是错误的。看这里http://api.jquery.com/jquery.ajax/

方法必须是 POSTGETPUT

$.ajax({
url: "LINK",
method: "POST",
data: {
“method”:“fruit-post”,
“data”:{
“red-fruits”:["Apple","Cherry","Tomato"],
“green-fruits”:["Grapes","Watermelon"],
“yellow-fruits”:["Lemon","Pear"],
“purple-fruits”:[]
}
},
dataType: "html",
cache: false,
success: function(data) {
}
});

关于javascript - 连接到服务器 AJAX 调用时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50941068/

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