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

来源:互联网 发布:怎样安装天正软件 编辑:程序博客网 时间:2024/04/30 23:09
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){

};

0 0
原创粉丝点击