Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda