2016-04-27 45 views
0

我想在5000秒後點燃get_convo,但是當我點擊一條消息後它會自動啓動。jquery沒有被告知閃電已被告知

$(".mes").click(function(){ 
     var user = $(this).attr("id"); 
     $("#convo").html(user); 
     $(".convo_mes").html("Loading conversation <img width='15' height='15' src='./img/load.gif'>"); 
     setTimeout(get_convo(user),5000); 
    }); 

    //get convo 
    function get_convo(user){ 
     $.post("./php/get_convo.php",{username:user},function(get_convo){ 
      $(".convo_mes").html(get_convo); 
     }); 
    } 

回答

1
setTimeout(function() {get_convo(user)}, 5000); 

如果不工作,那麼它可能只是因爲AJAX做什麼就是了。

+0

非常感謝! –

1

只要讀取setTimeout函數,函數就會被調用。你必須提供適當的功能。所以setTimeout可以稍後調用該函數。這將是解決方案:

$(".mes").click(function(){ 
     var user = $(this).attr("id"); 
     $("#convo").html(user); 
     $(".convo_mes").html("Loading conversation <img width='15' height='15' src='./img/load.gif'>"); 
     setTimeout(function(){ get_convo(user)},5000); 
    });