How to send serialize form data using JQuery if the input element is an array

后端 未结 14 678
庸人自扰
庸人自扰 2020-12-16 15:16

I have this piece of code in my PHP code:

while ($row = mysqli_fetch_assoc($result))
{
    extract($row);
    echo \"\";
    echo \"

        
14条回答
  •  春和景丽
    2020-12-16 16:05

    work correctly jquery =>

    var data = $('form').serialize();
                $.post(baseUrl+'/ajax.php',
                        {action:'saveData',data:data},
                        function( data ) {
                            alert(data);
                        });
    

    php =>

    parse_str($_POST['data'], $searcharray);
        echo ('
    ');print_r($searcharray);echo ('
    ');

    output =>

    [query] => 
    [search_type] => 0
    [motive_note] => 
    [id_state] => 1
    [sel_status] => Array
        (
            [8] => 0
            [7] => 1
        )
    

    and You can do whatever what you want like with array data, thanks to Aridane https://stackoverflow.com/questions/1792603

提交回复
热议问题