I have the following poll() function:
var pollTimeout = 5000;
(function poll(){
setTimeout(function(){
$.ajax({ url: "/ajax/livedata.php", success: function(data){
if (data[0] == 'success'){
// i'm doing some irrelevant updating here
}
poll();
}, dataType: "json"});
}, pollTimeout);
})();
It’s being executed every 5 seconds and everything works fine.
However, how can I execute this function manually? For example, I need to execute it here:
$("#status-update-form textarea").keyup(function(e){
if (e.keyCode == '13'){
var status = $(this).val();
$.get("/ajax/update-status.php", { 'status' : status },
function(data){
$("#status-update-form textarea").val('').blur();
// <-- I need to execute the poll here, so that
// the status is updated immediatelly after it's
// submitted, not when the poll fires seconds later
},'json'
);
}
});
Any idea how can I do this? If I try to fire poll(), it says the function doesn’t exist.
Convert your poll to a regular function