Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda