Answer the question
In order to leave comments, you need to log in
ajax request timeout?
There is a function that performs an ajax request on a button click.
function LoadQuest()
{
$.ajax({
type: "POST",
url: "/ajax/",
data: {
's_id': s_id,
'member_id': member_id,
'param': 'LoadQuest'
},
error: function()
{
document.getElementById('load_button').innerHTML = '<button type="button" tkey="loadmore_button">'+load_more+'</button>';
console.log(3);
},
beforeSend: function()
{
document.getElementById('load_button').innerHTML = '<button type="button" onClick="LoadQuest()">\
<div class="sk-spinner sk-spinner-wave">\
<div class="sk-rect1"></div>\
<div class="sk-rect2"></div>\
<div class="sk-rect3"></div>\
<div class="sk-rect4"></div>\
<div class="sk-rect5"></div>\
</div>\
</button>';
},
success: function(msg)
{
console.log(0);
msg = jQuery.parseJSON(msg);
if(msg['error'] == true)
{
document.getElementById('load_button').innerHTML = '<button type="button" tkey="error_14">'+msg['text']+'</button>';
console.log(1);
}
else
{
for(var i = 0; i < count(msg); i++)
{
console.log(2);
message += '<div class="footer">\
<div class="title">'+msg[i]['q_title']+'</div>\
<div class="quest-content">'+msg[i]['q_text']+'</div>\
</div>\
<div class="clearfix"></div>';
sid = msg[i]['q_id'];
}
s_id = sid;
document.getElementById("quest").innerHTML = message;
document.getElementById('load_button').innerHTML = '<button type="button" onClick="LoadQuest()" tkey="loadmore_button">'+load_more+'</button>';
}
}
});
}
Answer the question
In order to leave comments, you need to log in
remove the click handler from the button for the duration of the request.
It can be in a bunch of ways.
Remove handler from click event
var $button = $("button#send-ajax");
function clickHandler () {
// Отправка Ajax
// ...
// Отключаем обработку события клика
$button.off('click');
// Включаем через 3 секунды
setTimeOut(function () { $button.on('click', clickHandler); }, 3000);
}
// Включаем обработчик события
$button.on('click', clickHandler)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question