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

305
Views
How to call a Javascript AJAX function after button click?

I have searched this online but I am stuck. I am calling a JavaScript function button click. It does not work unless I wrap it in $(document).ready(function() {}). However, I need to run the function not just after page load, but right after button click.

HTML Button :

<a href="/Spend/Job" onclick="return getisModified()" class="btn btn-default">Config </a>

JavaScript :

var isModified;

function getisModified() {
  $.get("/Spend/Job/IsModified", function (data, status) {
    if (status === "success" && data && data.length > 0) {
      var dataObj = JSON.parse(data);
      isModified = dataObj.IsModifiedAny;
    }
  });

  if (isModified == true) { //if there are any modified rows
    var response = confirm("You have made changes without running Config. Continue anyway?")
    if (response) //user clicks OK
      {
        return true
      } else { //user clicks cancel
        return false
      }
  }
} 

The code works when i run it in the console. But not when it is called after button click.

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!