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

127
Vistas
jQuery Ajax post is not working

I know that there is a lot of questions like this out there, but I have been surfing them and other website for like 4 hours trying to figure this out. I am trying to get main.js to post the data via ajax and then the php should echo that data. If it does not work, it will echo "null". It keeps echoing "null" instead of "John". I know that the jquery and main.js links work, I have tested them. Here is main.js:

$(document).ready(function(){
    $.post("index.php", { test: "John"} );
});

And here is the php part of index.php:

<?php 
    $var = "null";
    if(isset($_POST['test'])) { 
    $var = $_POST['test'];
    }
    echo $var;
?>

I hope you can solve my problem, and thank you in advance.

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Download HTTP Trace chrome extension, traceback ajax call and share a screenshot.

https://chrome.google.com/webstore/detail/http-trace/idladlllljmbcnfninpljlkaoklggknp

over 4 years ago · Santiago Trujillo Denunciar

0

You are missing the callback function with the response from the server.

$.post( "index.php",{ test: "John"}, function( data ) {
  alert(data);
});

Or you can do something like this:

 $.post( "index.php",{ test: "John"})
  .done(function( data ) {
    alert( "Data Loaded: " + data );
  });

Please check the documentation Documentation

over 4 years ago · Santiago Trujillo Denunciar

0

Give this a shot

jQuery

var available agent = 1;
jQuery.ajax({
    type: "POST",
    url: "your-url",
    data: available_agent,
    dataType: 'json',
    cache: false,
    contentType: false,
    processData: false,
    success:  function(data){
        owner = data['round_robin_agent'];
    },
    error : function () {
       alert("error");
    }
});

PHP Script

public function round_robin() {
    //Do your work
    $round_robin_agent = 'rob';
    $results_array = array(
        'round_robin_agent' => $round_robin_agent
    );
    return json_encode($results_array);
}
over 4 years ago · Santiago Trujillo 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