Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php $.ajax转换为$http.post或get angular_Php_Ajax_Angularjs_Xmlhttprequest_Responsetext - Fatal编程技术网

Php $.ajax转换为$http.post或get angular

Php $.ajax转换为$http.post或get angular,php,ajax,angularjs,xmlhttprequest,responsetext,Php,Ajax,Angularjs,Xmlhttprequest,Responsetext,我正在构建一个投票应用程序,其中具有电子邮件地址的特定投票人只能投票一次 然而,我这里的代码运行得太慢了,请看我如何将下面的代码转换为$http.post角度代码,该代码返回我可以使用的响应 $scope.votecheck = function(item,emailid){ var email = emailid; if( typeof item !== 'undefined') { var jsonData = $.ajax({ type: "GET",

我正在构建一个投票应用程序,其中具有电子邮件地址的特定投票人只能投票一次 然而,我这里的代码运行得太慢了,请看我如何将下面的代码转换为$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");
})
};
那就这样叫吧

    $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");
})
};

问题可能出在votters.php脚本中。我的脚本工作正常,但av read ASSYNC:false会在暂停所有其他javascript执行时减慢web速度。。如果我能找到一种方法编写一个回调,返回超出$.ajax:S范围的success:functiondata