{"id":193,"date":"2017-08-01T09:12:25","date_gmt":"2017-08-01T09:12:25","guid":{"rendered":"http:\/\/info.juliusgoh.life\/?p=193"},"modified":"2018-01-09T04:56:47","modified_gmt":"2018-01-09T04:56:47","slug":"how-to-prevent-multiple-ajax-calling","status":"publish","type":"post","link":"https:\/\/info.juliusgoh.life\/?p=193","title":{"rendered":"How to prevent multiple ajax calling"},"content":{"rendered":"<p>1.Call a first function before calling second function(ajax)<br \/>\n2.In first function , check for a div with specific id&#8217;s length<br \/>\n3.In second function(ajax) most top append the div with specific id.<\/p>\n<p>Example:<br \/>\nEvent Scroll to Bottom -&gt; Call ajax:<\/p>\n<pre>$(window).on(\"scroll\", function() {\r\n     if($(window).scrollTop() == $(document).height() - $(window).height()){\r\n            beforeajaxcalling();\r\n    }\r\n});\r\n<\/pre>\n<p>Function to be called before calling ajax:<\/p>\n<pre>function beforecallingajax(){\r\n    if($(\"#running\").length &gt; 0){\r\n        console.log(\"AJAX IS RUNNING\");\r\n    }else{\r\n        callAjax();\r\n    }\r\n}\r\n<\/pre>\n<p>Function ajax with div(with id) appended:<\/p>\n<pre>function callAjax(){\r\n    $(\"<\/pre>\n<div id=\"running\"><\/div>\n<p>&#8220;).appendTo(&#8216;#somewhere&#8217;); &#8212;- REST OF AJAX&#8212; }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.Call a first function before calling second function(ajax) 2.In first function , check for a div with specific id&#8217;s length 3.In second function(ajax) most top append the div with specific id. Example: Event Scroll to Bottom -&gt; Call ajax: $(window).on(&#8220;scroll&#8221;, function() { if($(window).scrollTop() == $(document).height() &#8211; $(window).height()){ beforeajaxcalling(); } }); Function to be called before [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":219,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"_links":{"self":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/193"}],"collection":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=193"}],"version-history":[{"count":7,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions"}],"predecessor-version":[{"id":220,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/posts\/193\/revisions\/220"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=\/wp\/v2\/media\/219"}],"wp:attachment":[{"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/info.juliusgoh.life\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}