var app = angular.module("scoreApp", []); app.config(function($httpProvider) { $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8'; $httpProvider.defaults.headers.post['Accept'] = 'application/json, text/javascript, */*; q=0.01'; $httpProvider.defaults.headers.post['X-Requested-With'] = 'XMLHttpRequest'; $httpProvider.defaults.transformRequest = [ function(data) { var param = function(obj) { var query = ''; var name, value, fullSubName, subName, subValue, innerObj, i; for (name in obj) { value = obj[name]; if (value instanceof Array) { for (i = 0; i < value.length; ++i) { subValue = value[i]; fullSubName = name + '[]'; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; } // console.log(query); } else if (value instanceof Date) { query += encodeURIComponent(name) + '=' + encodeURIComponent(value.toJSON()) + '&'; } else if (value instanceof Object) { for (subName in value) { subValue = $.trim(value[subName]); fullSubName = name + '[' + subName + ']'; innerObj = {}; innerObj[fullSubName] = subValue; query += param(innerObj) + '&'; } } else if (value !== undefined && value !== null) { query += encodeURIComponent(name) + '=' + encodeURIComponent(value) + '&'; } } // console.log(query); return query.length ? query.substr(0, query.length - 1) : query; }; return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data; } ]; }); app.controller('scoreController', ['$scope','$http','$rootScope',function($scope, $http,$rootScope) { $scope.flag = false; var array = new Array(); for (var k = 0; k < 9; k++){ array.push({ subject_id : k }) } $scope.subjectArray = array; // $scope.cert_id = ""; $scope.goSearch = function() { if ($scope.cert_id == undefined || $scope.std_name == undefined) return; $scope.map = undefined; $http({ url : '../wish/std/searchNy.htm', method : 'post', data : { cert_id : $scope.cert_id, std_name : $scope.std_name, exam_id : $scope.exam_id } }).success(function(data) { if (data.success == false) { alert(data.errorMsg); $scope.flag = false; document.getElementById('cert_id').focus(); return; } $scope.flag = true; $scope.map = data.map; if($scope.map == undefined) { $scope.admisFlag = 'noAdmis'; } else { $scope.admisFlag = 'admis'; } }).error(function(data) { $scope.flag = false; alert('网络错误,请重试'); document.getElementById('cert_id').focus(); }); } $scope.changeStdName = function($event) { $scope.admisFlag = ''; if ($event.keyCode == 13) $scope.goSearch(); } $rootScope.openNewWindow = function(url) { window.open(url); }; $scope.download = function(){ $http({ url : 'std/score/download.htm', method : 'post', data:{ cert_id :$scope.cert_id } }).success(function(data) { $rootScope.openNewWindow('frame/file/download/template1.htm?file_name=/temp/' + data.entity); }).error(function(data) { alert('网络错误,请重试'); }); } }]);