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

128
Vistas
ajax call successful but no values in php

ajax success function alert data but on php side no data there GET array is empty

<script type="text/javascript">
    var  array={
    name:"amr",
    age:22
}
array =JSON.stringify(array);
$.ajax({
    url :"new.php",
    type : "GET",
    data :  {action:array},
    success: function(response){
        alert(response);
    },

});
</script>



<?php 
$var =json_encode($_GET['action']);
echo $var;
?>

enter image description here

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

0

The PHP code is executed on the server, the output of PHP is then sent to the client, the client executes JavaScript, not PHP. In your example you have two pages, ajax.php and new.php, in this example you don't need to use PHP in ajax.php page, since once the PHP present in ajax.php is executed on server and the output is sent to the client it will not change anymore.

This code:

<?php 
$var =json_encode($_GET['action']);
echo $var;
?>

should be into your new.php file, and only there, ajax.php will call from the client new.php, that will execute your PHP and will send back the output to the client, once you have the output on the client you can do with it whatever you want, for example this may be the source code in your ajax.php:

<script type="text/javascript">
    var  array={
    name:"amr",
    age:22
}
array =JSON.stringify(array);
$.ajax({
    url :"new.php",
    type : "GET",
    data :  {action:array},
    success: function(response){
    /*
     * This will write on your page (ajax.php) the response 
     * from the server, note that this is done with javascript,
     * not with PHP
     */
        document.write(response);
    },

});
</script>

You can also rename the file ajax.php to ajax.html, since no PHP is needed on this page.

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