HTMHell
HTMHell

Reputation: 6006

Send array through Ajax

I want to send an array to PHP through Ajax.

array = $('.def-mask :checkbox:checked').serialize();
$.ajax({
    url: 'ajax/battle.php',
    type: 'post',
    data: { playerReady: 1, attack: attack, defence: array },
    success: function(data) {
        alert(data);
    }
});

But when I do var_dump($_POST['defence']), I get string(), and not array(). Why do I get a string, and not an array?

Upvotes: 0

Views: 607

Answers (1)

Amir
Amir

Reputation: 4111

use .serializeArray() instead of .serialize() refer here

Upvotes: 1

Related Questions