angularJS 怎样将下面类型的json数据从前端传到后台
//定义全局变量
$scope.countRight=0;
$scope.countError=0;
//初始化学生答案
angular.forEach($scope.errQueBook, function (data) {
data.question.yourAns="";
});
// 提交试卷
$scope.submit=function() {
var saveDataAry=[];
var status=0;
var flag=true;
var resultData;
angular.forEach($scope.errQueBook, function (data) {
if (flag) {
var name = data.question.questionID;
var temp = "input[name='" + name + "']:checked";
var value = $(temp).val();
data.question.yourAns = value;
if(data.question.yourAns==data.question.answer){
$scope.countRight+=1;
status=1;
}
else{
$scope.countError+=1;
status=0;
}
resultData={"id":name,"result":status};
saveDataAry.push(resultData);
}
});
var url =errQueBookurl+ '/updateErrQue';
var config = {
headers: {
'Content-Type': "application/x-www-form-urlencoded"
}
};
var data =JSON.stringify(saveDataAry);
$http.post(url, data, config).success(function (data) {
alert(1);
}).error(function (status, statusText) {
dialogMsg(statusText);
alert(2);
});
document.getElementById("retest").style.display="none";
document.getElementById("result").style.display="block";
}
数据如下
[{"id":7156,"result":0},{"id":7113,"result":0},{"id":7110,"result":1},{"id":7069,"result":0},{"id":7179,"result":0},{"id":7169,"result":0},{"id":7202,"result":1},{"id":12098,"result":0},{"id":12089,"result":0},{"id":7060,"result":0},{"id":7095,"result":0},{"id":7121,"result":0},{"id":12090,"result":0},{"id":7086,"result":1},{"id":13378,"result":0},{"id":7323,"result":0},{"id":7284,"result":1},{"id":7261,"result":0},{"id":13292,"result":0},{"id":13334,"result":0},{"id":13318,"result":1},{"id":7220,"result":0},{"id":7279,"result":0},{"id":13279,"result":1}]