oedin oedin - 1 year ago 76
Ajax Question

jQuery prevent multiple ajax calls

I have

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">
<ul class="list-unstyled">
<i class="fa fa-building"></i>
<strong> Address</strong>: -
<i class="fa fa-phone"></i>
<strong> Phone #</strong>: -
<a id="corp1" class="small-box-footer" href="1">
More info
<i class="fa fa-arrow-circle-right"></i>

the following script will make that
element perform ajax call

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

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

How do I solve this?

Answer Source

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