angularjs $http调用接口的方式:
$http.get("/merchantmall/merchant.json")
.success(function(data, status, headers, config) {
console.log(arguments);
})
.error(function(data, status, headers, config) {
console.log(arguments);
})
$http({url: "/merchantmall/merchant.json", })
.success(function(data, status, headers, config) {
console.log(arguments);
})
.error(function(data, status, headers, config) {
console.log(arguments);
})
var promise = $http({
method: 'GET',
url: '/api/users.json'
});
promise.then(function(resp) {
// resp是一个响应对象
}, function(resp) {
// 带有错误信息的resp
});
var promise = $http({
method: 'GET',
url: '/api/users.json'
});
promise.success(function(data, status, headers, config) {
// 处理成功的响应
});
promise.error(function(data, status, headers, config) {
// 处理非成功的响应
});

本文介绍了在AngularJS中使用$http服务来调用API的不同方式,包括get请求和其他请求方法,并展示了如何处理成功及失败的响应。
3409

被折叠的 条评论
为什么被折叠?



