How To Avoid Or Stop Multiple Ajax Request
I am using the flotchart plugin, and I was trying to know when and where the user hovers on the chart and get more information from database regarding that chart value. For example
Solution 1:
You can do this by adding a flag to the top of the function which checks to see if the ajax call has been fired. Here is some sudo code, obviously you will need to make this work with your example.
var isAjaxing = false
$().on("click", function(){
if(isAjaxing) return;
isAjaxing = true;
$.ajax(url, function(){
isAjaxing = false;
})
})
This will lock out the function until the ajax call is complete.
Solution 2:
I would recommend using this jQuery plugin and throttle your request. It also contains the code samples.
You can do something like this
$("#visitor-chart").on("plothover", function(event, pos, item) {
...
$.throttle(makeYourAjaxCallHere, 300)
...
});
Post a Comment for "How To Avoid Or Stop Multiple Ajax Request"