Skip to content Skip to sidebar Skip to footer

Send Javascript Array Through Jquery Ajax Post

What I want to do is send an JavaScript Array to a PHP file. This is what I got: var mydata = []; console.log(document.getElementsByTagName('input')[0].name); for (

Solution 1:

Try to use this code and see the changes.

remove the contentType: 'application/json', dataType: 'json'

And change var mydata = [] into var mydata = {}

your ajax should look like this

        $.ajax({
            method: "POST",
            url: "q.php",
            data: {'lol': mydata}
        })
        .done(function( msg ) {
            alert( "Data Saved: " + msg );
            $('#debug').html(msg);
        });

You dont have to stringify your mydata because you already decleared it as object.

Hope it helps

Post a Comment for "Send Javascript Array Through Jquery Ajax Post"