AJAX:异步请求不返回布尔值

时间:2017-04-02 21:00:12

标签: javascript jquery ajax asynchronous boolean

我试图返回true或false,具体取决于用户令牌和&在本地存储中的作用是可以的。出于某种原因,我作为回应得到了不确定......你们能帮助我吗?

  function isLogged(roleNeeded) {
    var token = "asd";//localStorage.getItem("token");

      function handleResponse(data){
          ajaxresponse = data;

          var val;
          var localRole = "s";//localStorage.getItem("role");

          val = (data.status === "ok" && localRole === roleNeeded);
          return val;
      }
      loadAjax(token, handleResponse)
  }
  function loadAjax(token, handleResponse) {
      $.ajax({
          url: 'http://localhost/users/login/verify',
          method: 'GET',
          headers: {token: token},
          success: function(data)
          {
            handleResponse(data)
          }
      });
  }

0 个答案:

没有答案