0

Trying to have data passed to a php script so the said data can be added to the session. The debug console log returns are the following: the quant array is correct and typeof is object, the JSON.stringified data's type is string , lastly success from the ajax success.
In the PHP script var_dump return is NULL

    $('#bigsubmit').click(function() {
    var quant = [];
    $('.input-number').each(function() {
        var tmp = {};
        tmp.id = this.id;
        tmp.qu = $(this).val();

        quant.push(tmp);
    });
    console.log(quant);
    var data = JSON.stringify(quant);
    console.log(typeof(data));
    $.ajax({
        type: "POST",
        url: url,           
        data: {
            data: data
        },
        success: function() { 
            console.log("success");     
        }
    }); 

the php script (url var)

<?php
session_start();
$_SESSION['test'] = $_POST['data'];
var_dump($_SESSION['test']);

?>
Nipun
  • 990
  • 1
  • 16
  • 25
40oz
  • 45
  • 8
  • Can you try `var_dump`ing `$_POST` to see all of its elements? Also try changing your variable names, there's a lot of them named `data`, (this probably won't fix it though). – Ethan Dec 19 '18 at 23:54
  • _"In the PHP script var_dump return is `NULL`"_ I'm curious about this part. How exactly are you viewing this? If you're just opening the PHP URL in your browser, you will be overwriting `$_SESSION['test']` with an undefined value – Phil Dec 19 '18 at 23:59
  • yea i cant see the output on the site where the ajax is executed, i check it by opening the php script on a separate tab, so i wouldnt be able to access the post data there. – 40oz Dec 20 '18 at 00:01

1 Answers1

1

Your success callback function isn't taking in a parameter, try changing to this,

success:function(data) {
   console.log(data);
}
Ryan Wilson
  • 10,223
  • 2
  • 21
  • 40