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

84
Views
Unable to call ajax function but console.log and alert working of that JS file

hello everyone working on PHP MVC. Facing issue while submitting form using ajax, in Network area of Inspect elements not able to see that perticular ajax being called. If i try to run console.log or alert in that JS then it's working fine. here is my JS code. Thanks in advance.

$(document).ready(function(){
    $("button#applyLeave").click(function(){
        console.log('asgnduser');
        var leaveType = $("#leavetype").val();
        var leaveDate = $("#leavedate").val();
        var leaveTime = $("#leavetime").val();
        var leaveDateRange = $("#reservation").val();
        var leaveReason = $("#leavereason").val();
        console.log(leaveType + ' ' +leaveDate+ ' ' +leaveTime + ' ' +leaveDateRange + ' ' +leaveReason);
        alert(APP_URL + '/apply-leave');

        var dataString = 'leaveType='+ leaveType + '&leaveDate='+ leaveDate + '&leaveTime='+ leaveTime + '&leaveDateRange='+ leaveDateRange + '&leaveReason='+ leaveReason;
            // AJAX Code To Submit Form.
            $.ajax({
                type: "POST",
                url: APP_URL + '/apply-leave',
                data: dataString,
                cache: false,
                success: function(result){
                    // console.log('Success: '+result);
                    // alert('Data Saved Successfully');
                    if (result == 'success') {
                        alert("Leave applied!!!");  
                        window.location.href = APP_URL + '/leaves';
                    }   
                },
                error: function(result){
                    // console.log('Error: '+result);
                }
            });
        return false;
    });
});
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I just tried out your code in code sandbox environment and it's working properly. If you don't see any requests going out then most likely your button or it's ID is not existing in the HTML.

Here's my example code sandbox url: https://codesandbox.io/s/ecstatic-hugle-7rfnt?file=/src/index.js

You can do a compare with your code and see the difference.

about 4 years ago · Juan Pablo Isaza Report

0

Did silly mistake over here. In inspect element Network tab recording of network log was turned off because of that wasn't able to see ajax there. Turning on I was able to see it.

about 4 years ago · Juan Pablo Isaza Report
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!