AngularJS中$ http POST失败,谷歌REST客户端成功

时间:2015-11-13 09:07:59

标签: javascript json angularjs http-post

我有以下代码:

updatelist = 
[
{
parser: {
delimiter: "",
parser_name: "History Record",
id: 3675,
isEnabled: "Y",
isFixedWidth: "N",
parsertype: "Table",
postprocessing: ""
},
parserdetail: [
{
ColumnName: "",
ColumnWidth: 0,
Delimiter: "", 
EOL: "Y", 
KeySignature:"Boot History Record", 
KeySignaturePosition: "Left",
OrderNum: 1,
ParserSection: "header",
TagName: "",
ValueType: ""
},

{
ColumnName: "S.No.",
ColumnWidth: 4,
Delimiter: "", 
EOL: "Y", 
KeySignature:"", 
KeySignaturePosition: "",
OrderNum: 1,
ParserSection: "body",
TagName: "SNumber",
ValueType: "nums"
}
]
}
]

$http({
    method: 'POST',
    url: "https://myurl/parserrulesupdate",
    data: $.param(updateList),
    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
    responseType: 'json'
})
.then(function(response) {
    returnData.resolve(response.data);  // returns list of ids
})
.catch(function(response) {
   console.error('POST error', response.status, response.data);
   returnData.reject();
})            

上述http调用失败,响应500

但是,如果我通过Google REST客户端使用相同的数据执行相同的POST,则会成功。我此刻正在挠头。如果你能说明它为什么会发生,我会非常感激。

1 个答案:

答案 0 :(得分:0)

我不知道你的服务器端代码,特别是输入对象,但我认为问题可能在这里:

data: $.param(updateList)

尝试直接传递对象:

data: updateList