Javascript 如何在AngularJS中检查xmlhttpRequest
当我的状态为200时,如何检查Javascript 如何在AngularJS中检查xmlhttpRequest,javascript,jquery,angularjs,xmlhttprequest,Javascript,Jquery,Angularjs,Xmlhttprequest,当我的状态为200时,如何检查XMLHttpRequest,为什么它不检查我的xhr angular.module("productManagement").controller('Employee', function ($scope, EmployeeService) { var xhr = new XMLHttpRequest(); $scope.GetdataBySubmit = function () { var GetData = EmployeeService.Ge
XMLHttpRequest
,为什么它不检查我的xhr
angular.module("productManagement").controller('Employee', function ($scope, EmployeeService) {
var xhr = new XMLHttpRequest();
$scope.GetdataBySubmit = function () {
var GetData = EmployeeService.GetEmployeeData();
debugger;
GetData.then(function(d) {
if (xhr.status == "200") {
$scope.Employee = d.data;
$('#TadleData').show();
} else {
console.log("")
}
})
}
})
这里我正在更新我的GetEmployeeData
code
angular.module("productManagement").service("EmployeeService", function
($http) {
this.GetEmployeeData = function () {
var x=$http({
url: "http://localhost:9632/Api/Employee",
method:"Get",
data:JSON.stringify()
})
return x;
}
})
无需定义和使用
xhr
变量
在使用$http
并返回Promise
时,请使用success
回调处理程序response
对象
GetData.then(function (response) {
if (response.status == 200) {
$scope.Employee = response.data;
$('#TadleData').show();
}
}, function (response) {
console.log("Do something on error")
})
显示
GetEmployeeData
函数的代码,检查我认为是响应的d
。所以只要d.status
就行了你的xhr
从来没有被使用过。。。?