angularjs$http是请求还是接口

2025-04-04 16:07:32
推荐回答(1个)
回答1:

H5edu教育html5开发 培训为您解答:
angularjs $http调用接口的四种方式:
1.$http.get("/merchantmall/merchant.json")
.success(function(data, status, headers, config) {
console.log(arguments);
})
.error(function(data, status, headers, config) {
console.log(arguments);
})

2.$http({
url: "/merchantmall/merchant.json",
}).success(function(data, status, headers, config) {
console.log(arguments);
}).error(function(data, status, headers, config) {
console.log(arguments);

})

3.var promise = $http({
method: 'GET',
url: '/api/users.json'
});

promise.then(function(resp){
// resp是一个响应对象
}, function(resp) {
// 带有错误信息的resp
});

4.var promise = $http({
method: 'GET',
url: '/api/users.json'
});
promise.success(function(data, status, headers, config){
// 处理成功的响应
});
// 错误处理
promise.error(function(data, status, headers, config){
// 处理非成功的响应
});