block double request while ajax is pending
i really need to understand how block the requests ajax while is pending.
Let me exaplain a example:
I have a input type called "share" and when i write something and press
enter ajax take the result and it insert inside mysql. If i do this
pressing a lot of time the enter button it take more results like how many
times i pressed enter even if there is a control in php. I think is a
problem of the request ajax because the control php I'm sure is right.
Thank you so much.
this is the code of example:
form
<input type="text" class="share">
Js
$.fn.enterKey = function (fnc) { // function for check when i press enter
return this.each(function () {
$(this).keypress(function (ev) {
var keycode = (ev.keyCode ? ev.keyCode : ev.which);
if (keycode == '13') {
fnc.call(this, ev);
}
})
})
}
$('.share').enterKey(function() { // ajax request
var comment = $(this);
if (comment.val() != "") {
$.ajax({
type: "POST",
url: add_comment.urlRemove,
data: "text=" + comment.val(),
success: function(html) {
comment.val('');
},
error: function(){
alert('Error on ajax call');
}
});
} else {
return false;
}
});
}
No comments:
Post a Comment