[英]$.ajax conversion to $http.post or get angular
我正在构建一个投票应用程序,其中具有电子邮件地址的特定选民只能投票一次,但是我在这里的代码运行太慢,请问我如何将以下代码隐藏到$ http.post角度代码中,以返回我可以使用的响应
$scope.votecheck = function(item,emailid){
var email = emailid;
if( typeof item !== 'undefined')
{
var jsonData = $.ajax({
type: "GET",
url: 'ajax/voters.php?id='+item.ID+'&email='+email,
dataType: 'text',
async: false
}).responseText;
if(jsonData === "CanVote"){
return true;
}
else{
return false;
} //return "canvote";
}
}
像这样使用诺言 ...
$scope.voteCheck = function(email, id) {
var deffered = $q.defer();
$http.get('ajax/voters.php?id='+item.ID+'&email='+email, {
}).success(function(data) {
deffered.resolve(data);
});
return deffered.promise;
};
然后叫这样的话...
var votePromise = $scope.voteCheck($item.ID, email);
votePromise.then(function (data) {
return(data === "CanVote");
})
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.