Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!