aysnch:false需要很长时间才能加载async true返回undefined angularjs ng-show

Hello am aving a problem with this code, it hangs the user browser which isn't good from the end user's perspective.. but turning the async to true returns undefined because the server isnt in a ready state to return the responseText.. wi ld really like someone to give me an idea of ow to resturcture this code.. because its being performed in the html ng-show @ the font end

controller:

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

html:

<div class="row text-center">
<div class="col-md-10 col-md-offset-1" ng-show="!votecheck(item,me.email)">
<p class="contest-text voters"><a class="btn btn-info btn-block img-rounded" ng-disabled="true"><b>Thanks For Voting</b></a>&nbsp;&nbsp;</p>
</div>
<div class="col-md-10 col-md-offset-1" ng-show="votecheck(item,me.email)">
<p class="contest-text voters"><a class="btn btn-primary btn-block img-rounded" ng-click="upVote(item,me.email);"><b> VOTE</b></a>&nbsp;&nbsp;</p>
</div>

php:

<?php
include('../include/connect.php');
$id = $_GET['id'];
$emailid = $_GET['email'];
$query="select * from voters  where votedid='$id' and votersemail ='$emailid'";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$rowcount = $result->num_rows;
if($rowcount === 0)
{
echo "CanVote";
}
else{
    echo "cantvote";
}

?>

thanx guyz

Are you comibining jquery and the angular? Angular is asynchronous by nature and simple $http.get with a promise can solve the issue.

 your parameters should be passed here.
 var url = 'ajax/voters.php?id='+item.ID+'&email='+email;
 $http.get('url')
 .success(function(data)
 {

   // do your operarion here;
  })
.error(function(data){
//do what ever u want on error.
});

Hope this helps.

First of all, you should use $http service (https://docs.angularjs.org/api/ng/service/$http) and not $.ajax.

If i understood what you were trying to do, then you should not show the "vote" link until you are sure that the current user is able to vote. This can be done this way:

// TODO : fill canVote object with your item list,
// I guess you're using ng-repeat, and have an array of items.
// This object will be used to determine if the user can vote or not.
// Key : item ; value : boolean
$scope.canVote = {
  item1: false
};    
$scope.votecheck = function(item,emailid){
    var email = emailid;
    if( typeof item !== 'undefined')
    {
      $http.get('ajax/voters.php?id='+item.ID+'&email='+email).then(
         function cb_success(response) {
           $scope.items[item] = response.data === "CanVote";
      }, function cb_failure(response) {
           console.error(response);
      });
    }
}
angular.forEach($scope.canVote, function (status, item) {
  $scope.votecheck(item, $scope.me.email);
});

This is how you should do with your html :

<div class="row text-center">
  <div class="col-md-10 col-md-offset-1" ng-show="canVote[item]">
    <p class="contest-text voters"><a class="btn btn-info btn-block img-rounded" ng-disabled="true"><b>Thanks For Voting</b></a>&nbsp;&nbsp;</p>
  </div>
  <div class="col-md-10 col-md-offset-1" ng-show="canVote[item]">
    <p class="contest-text voters"><a class="btn btn-primary btn-block img-rounded" ng-click="upVote(item,me.email);"><b> VOTE</b></a>&nbsp;&nbsp;</p>
  </div>

Since you did not provide any JSFiddle (w/e), I haven't been able to test it. Let me know if you have some issues.