Home Ajax Post to PHP returning empty array
Reply: 0

Ajax Post to PHP returning empty array

user871
1#
user871 Published in April 26, 2018, 1:46 pm

I need to pass a json object from JS to PHP, and it will pass, but the result is an empty array.

Ajax request in 'adopt.php':

var info = JSON.stringify(filteredArray);
$.ajax({
    type: 'POST',
    url: 'ajax.php',
    data: {'info': info},
    success: function(data){
        console.log(data);
    }
});

ajax.php code:

if(isset($_POST['info'])){
    $_SESSION['array'] = $_POST['info'];
}

back in adopt.php, later:

if(isset($_SESSION['array'])){
    $arr = $_SESSION['array'];
    echo "console.log('information: ' + $arr);";
}

in both of the console.logs, it returns an empty object. Does anybody know what could be causing this? (i've tried just passing the json without stringifying it, but it throws a jquery error whenever i do this.)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.54608 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO