Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

248
Views
How to get variable value at once while post in ajax?

$(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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!