网络编程 
首页 > 网络编程 > 浏览文章

angularjs $http调用接口的方式详解

(编辑:jimmy 日期: 2024/5/20 浏览:3 次 )

如下所示:

$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调用接口的方式详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

上一篇:AngularJS使用$http配置对象方式与服务端交互方法
下一篇:Javascript格式化并高亮xml字符串的方法及注意事项
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网