我有一个字符串:
'{format:“json”,用户:“user”,密码:“password”}'
我希望使用jQuery的AJAX发送所有这些数据。我试过这种方式(requestData ['data']是字符串):
folderBrowserDialog.SelectedPath = @"\\" + HostAddress + @"\c$"
我是否必须以某种方式对字符串进行编码?
答案 0 :(得分:0)
你可以发送整个对象,这不是问题:
var jsonObj = {format: "json", user: "user", password: "password"};
$.ajax({
url: requestData['url'],
type: jsonObj,
data: requestData['data'],
error: function(xhr) {
alert("failed");
},
dataType: 'json',
success: function(data, textStatus, xhr) {
alert("success");
}
});
答案 1 :(得分:0)
var datum = {
format: "json",
user: "user",
password: "password"
};
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: url, // your url
dataType: "json",
data: JSON.stringify(datum),
success: function(response) {
var result = response;
}
});