i am clicking a button and calling a function... when i click button twice the
data is inserting twice
in mysql database how can i avoivd it in my case..?
This my dynamic html:
<button type="button"
href="javascript:;"
class="btn btn-primary"
onclick="jobResponse('yes',<?php echo $myjobs['id_job'];?>)">
Subimt </button>
This is my function with ajax call:
<script type="text/javascript">
function jobResponse(res,jobId){
var frm_data = { res : res,
jobId : jobId
}
$.ajax({
//ajax resopons and requst
});
}
</script>
How can i resolve this issue..?
Pass the button reference and disable it and later when ajax is completed enable it again if needed.
<button type="button" href="javascript:;" class="btn btn-primary" onclick="jobResponse(this, 'yes',<?php echo $myjobs['id_job'];?>)"> Subimt</button>
<!-- ----------------^^^^----
<script type="text/javascript">
function jobResponse(ele, res, jobId) {
var frm_data = {
res: res,
jobId: jobId
};
// disable the button
$(ele).prop('disabled', true);
$.ajax({
//ajax resopons and requst
complete: function() {
// enable the button if you need to
$(ele).prop('disabled', false);
}
});
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With