这里我有名为 item 的变量并包含以下数据:
{
__metadata: {
"type": "SP.Data.ClinicalTestingPhaseIIListItem"
},
Control: 1,
Randomization: 2,
Blindings: 3,
Groups: 4,
DoseTitration: 5,
Stratification: 6,
PatientsDoseLevel: 7,
TumourResponse: 8,
DetermineWarrants: 9,
Title: 1
}
现在,当我将它传递给下面编写的 ajax 调用时,经过一番研究后出现错误,我得到的结论是数据以字符串格式而不是对象传递。
Microsoft.SharePoint.Client.InvalidClientQueryException
: A node of typePrimitiveValue
was read from the JSON reader when trying to read the start of an entry. AStartObject
node was expected.
下面是我的ajax调用
jQuery.ajax({
url: requestUri,
type: "POST",
data: JSON.stringify(item),
headers: header,
success:function(){
alert("List itme Inserted Sucessfully");
},
error: function(data){
console.log(data);
alert(data.responseText);
alert("Error Occured");
}
});
最佳答案
删除 JSON.stringify 并查看
jQuery.ajax({
url: requestUri,
type: "POST",
data: item,
headers: header,
success:function(){
alert("List itme Inserted Sucessfully");
},
error: function(data){
console.log(data);
alert(data.responseText);
alert("Error Occured");
}
});
关于javascript - 将包含字符串数据的变量转换为 JavaScript REST API 的 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24017053/