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

223
Vistas
JQuery variable sent with AJAX to PHP gets 'null' on var_dump();

As the title describes it, I cannot get the value from my JQuery variable into a PHP one.

My JQuery code is like this:

$(document).ready(function() {
  var mbscr = 0;

  function checkSize() {
    if ($("#orientation").css("width") == "200px") {
      var mbscr = 1
    } else { 
      var mbscr = 2 
    }

    $.ajax({
      type:"POST",
      url: './a/cmn.arr.php',
      data: { mbscr : mbscr },
      cache: false,
      success: function(data) {
        console.log(data);
      }
    });
    return false;
  };

  checkSize(mbscr);

  $(window).resize(checkSize);
});

The PHP one is:

if(isset($_POST['mbscr']) && !empty($_POST['mbscr'])) {
    $_get_mbscr = $_POST['mbscr'];
}

var_dump($_get_mbscr);

If I use alert() instead of console.log(), the JQuery parts does its job, it alerts me what it should. My problem is I always get a null value for var_dump(), even when I do var_dump($_POST['mbscr']).

Any help will be appreciated, thank you.

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

0

You code should work. But if I understood right - you trying to see post data just while entering page? If you do so - you'll see array(0) because when you open page - request is GET. You can see real post result via network debugger (dev tools etc.)

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