Angularjs 数据请求和数据,以及获取地址栏信息提交service

本文介绍了一个使用AngularJS实现的服务层设计案例,其中包括了通过HTTP请求获取数据的方法(包括GET和POST),并提供了处理地址栏参数的功能。这些方法能够帮助开发者更好地组织与服务器交互的逻辑。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

app.service("configService", function($http, http, errorMsg, wxUrl, errUrl,loadUrl,walletUrl){
//post获取数据


this.post = function(url, params, success){
$http.post(http + url, params).success(function(resp){
result(resp, success, function(resp){});
}).error(function(resp) {
layer.msg(errorMsg);
});
}

//post获取数据(带错误方法)
this.postWithError = function(url, params, success, error){
$http.post(http + url, params).success(function(resp){
result(resp, success, error);
}).error(function(resp) {
layer.msg(errorMsg);
});
}


//get获取数据
this.get = function(url, success, skipAuth){
$http.get(http + url).success(function(resp){
if (skipAuth) {
success(resp);
} else {
result(resp, success, function(resp){});
}
}).error(function(resp) {
layer.msg(errorMsg);
});
}

//get获取数据(带错误方法)
this.getWithError = function(url, success, error){
$http.get(http + url).success(function(resp){
result(resp, success, error);
}).error(function(resp) {
layer.msg(errorMsg);
});
}

//获取地址栏参数
this.getUrlParam = function(name){
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substring(1).match(reg); 
        if (r != null) return decodeURI(r[2]);//if (r != null) return unescape(r[2]);
        return '';

}

});


function result(resp, success, error){

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值