$(document).ready(function(){
var flag = true;
$(".hold").click(function(){
if(flag){
result = 'desc';
flag = false;
}
else{
result = 'asc';
flag = true;
}
console.log("do ajax, sorttype = " + result);
/*
$.ajax({
type:"POST",
data:{"_token":"{{ csrf_token() }}", "sorttype":result},
url:BASE_URL+"/short_emp",
success:function(data){
$("#test").html(data);
}
})
*/
});
});
<input type="button" class="hold" value="Hold">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
In the above code I am simply trying to post result value at once but what happen when I click first time it run at once but when I click button again then it run twice. So, How can I resolve this problem?