Send multiple checkbox data to PHP via jQuery ajax()

后端 未结 6 1106
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-28 08:31

I want to submit a POST form that contains a textarea field and an input field(s) (type=\"checkbox\" with an arbitrary/variable number of checkboxes) on my website via jQuer

6条回答
  •  天涯浪人
    2020-11-28 09:17

    Yes it's pretty work with jquery.serialize()

    HTML

    JQuery

    function submitForm() {
    var form = document.myform;
    
    var dataString = $(form).serialize();
    
    
    $.ajax({
        type:'POST',
        url:'myurl.php',
        data: dataString,
        success: function(data){
            $('#myResponse').html(data);
    
    
        }
    });
    return false;
    }
    

    NOW THE PHP, i export the POST data

     echo var_export($_POST);
    

    You can see the all the checkbox value are sent.I hope it may help you

提交回复
热议问题