oedin oedin - 4 months ago 21
Ajax Question

jQuery prevent multiple ajax calls

I have

<a>
element in the web page that loaded via ajax:

<div class="small-box bg-aqua">
<div class="inner">
<div class="col-xs-4 text-center">
<h2>___</h2>
<p>____</p>
<ul class="list-unstyled">
<li>
<i class="fa fa-building"></i>
<strong> Address</strong>: -
</li>
<li>
<i class="fa fa-phone"></i>
<strong> Phone #</strong>: -
</li>
</ul>
</div>
<a id="corp1" class="small-box-footer" href="1">
More info
<i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div>


the following script will make that
<a>
element perform ajax call

$('body').on('click', 'a[id^="corp"]', function(e) {
call_master('corporate/get_detail', $(this).attr('href'));
e.preventDefault();
});


When clicking the link only once multiple ajax calls are generated.
enter image description here

How do I solve this?

Answer

change $('body').on() with $('body').one() and the problem solved, thanks everyone _ :)

Comments