我无法弄清楚我是否可以在数据标签中发送数组: 我的客户端JS代码如下:
$.ajax({
url: '/mobiledoc/jsp/aco/Beneficiary/ptmmview.jsp',
data: {
"action":"savePatientRecords",
"ptId":strPtId,
"PatientVal":PatientVal,
"Qid":Qid,
"QType":QType
"Array" : ??
},
dataType: 'text',
type: 'post',
success: function (responseMsg) {
// gets the response message back from server
loadMilestoneData();
alert(responseMsg);
答案 0 :(得分:0)
服务器通常不会读取这样的数组。为了小心,首先在客户端上展平数组:
data: {
...
"Array" : theArray.join(',') // beware of values with ',' in them
}
在服务器上,将数组拆分为“,”。
答案 1 :(得分:-2)
是的,你可以。首先使用方法而不是类型发布。像这样......
method: 'post'
JQuery应该为您序列化数据。
$.ajax({
url: '/mobiledoc/jsp/aco/Beneficiary/ptmmview.jsp',
data: {
"action": "savePatientRecords",
"ptId": strPtId,
"PatientVal": PatientVal,
"Qid": Qid,
"QType": QType,
"Array": [ 1, 2, 3 ]
},
dataType: 'text',
method: 'post',
success: function (responseMsg) {
// gets the response message back from server
loadMilestoneData();
alert(responseMsg);
}
});
如果没有,则使用 JSON.stringify 将对象/数组转换为字符串。
$.ajax({
url: '/mobiledoc/jsp/aco/Beneficiary/ptmmview.jsp',
data: JSON.stringify({
"action": "savePatientRecords",
"ptId": strPtId,
"PatientVal": PatientVal,
"Qid": Qid,
"QType": QType,
"Array": [ 1, 2, 3 ]
}),
dataType: 'text',
method: 'post',
success: function (responseMsg) {
// gets the response message back from server
loadMilestoneData();
alert(responseMsg);
}
});