我有JSON响应,我必须在我的ajax调用中发布,但我不知道该怎么做。
JSON回复:
{
"iASensorTypePresetRequest": [{
"sensorPresetTypeId": "1",
"min": "30",
"max": "50"
}, {
"sensorPresetTypeId": "3",
"min": "1",
"max": "200"
}, {
"sensorPresetTypeId": "5",
"min": "true",
"max": "NA"
}, {
"sensorPresetTypeId": "6",
"min": "false",
"max": "NA"
}
]
}
我的代码如下:
var formData = $scope.PresetObject;
var reqHeader = {
method: 'POST',
url: getAPI_URL('221') + $scope.selectedUseCase,
data: formData
};
ajaxService.AjaxCall(SuccessFunction, ErrorFunction, reqHeader);
我已发布对象,但我必须将其发布在'iASensorTypePresetRequest'
的数组中我已经编写了服务'ajaxService'并在其中编写了函数'SuccessFunction'在成功函数中我调用了$ http服务我也编写了错误函数并从控制器调用了'AjaxCall'服务函数。
我的问题是如何在ajax调用中发布包含对象的数组?
答案 0 :(得分:-1)
我在与后端通信时使用$ http服务。我建议将所有后端连接放入服务中。我称之为我的datacontext。
这是$http文档
的链接 var req = {
method: 'POST',
url: 'http://example.com',
headers: {
'Content-Type': undefined
},
data: { test: 'test' }
}
$http(req).then(function(){...}, function(){...});
如果你的api是RESTful,你可以使用$ resource factory。