How to pass file data with AJAX and jQuery?

前端 未结 4 911
心在旅途
心在旅途 2020-12-11 05:18

I\'m trying to create a form that allows a user to fill out data and if an option is checked a div opens up and the user has the option to upload a file along with their sub

4条回答
  •  难免孤独
    2020-12-11 06:14

    There are two ways to do it, one is pass parameters if you have less variables in you form..

    $post('url',{param1:$("#name").val(),param2:$("#middle").val()},function(data){
     //Action as per data returned from php code
    });
    

    Another method is serialize() method.

    $post('url',{param1:$("form").serialize()},function(data){
     //Action as per data returned from php code
    });
    

提交回复
热议问题