gpt4 book ai didi

ajax - 如何从 jQuery 发送 json 数据?

转载 作者:行者123 更新时间:2023-12-02 05:08:51 24 4
gpt4 key购买 nike

我正在尝试发送 JSON 字符串

var json = {"city":value1, "country":value2};
$.ajax({
url : url,
data : json,
dataType : 'json',
success : function(response) {
alert(response);
}
})

在我进行 ajax 调用的 URL 中,我不知道如何在那里获取此字符串值?我应该使用什么request.getParameter?参数中的值应该是什么?

最佳答案

Ajax 请求:

 var jsonObj= { jsonObj: [... your elements ...]};

$.ajax({
type: 'post',
url: 'Your-URI',
data: JSON.stringify(jsonObj),
contentType: "application/json; charset=utf-8",
traditional: true,
success: function (data) {
...
}
});

在服务器端:

String city =    request.getParameter("city");

String country= request.getParameter("country");

关于ajax - 如何从 jQuery 发送 json 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15837842/

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