weixin_33696822 2017-07-09 15:51 采纳率: 0%
浏览 26

对Ajax使用回调

I want to prevent a function to execute before get a value from ajax, I'm trying using async:false it works but deprecated. So, I'm using callback like what I found on internet. It's works too, but the browser still tell me if the callback is not the function. Here's my code

function User() {
    this.nama;
    this.nis;
    this.pass;
    this.role;
    this.url = "http://localhost/elearning-web/";
    
    this.Login = function(call) {
        $.ajax({
            type:"POST",url:this.url+"dologin.php",data:"nis="+this.nis+"&pass="+this.pass,
            success:function(e){
                call(e);
            }
        });
    }
}

When I check the console.log it's show what I want to display, but the browser tell me if the call (callback) is not a function. Thanks in advance

</div>
  • 写回答

3条回答 默认 最新

  • ℙℕℤℝ 2017-07-09 15:58
    关注

    The call argument, that you are passing to the method Login must be a function, for example:

    var call = somethingFunction(){ return 'called!';}
    var user = new User();
    user.Login(call) 
    
    评论

报告相同问题?