Serialize file type jQuery

后端 未结 4 1596
长发绾君心
长发绾君心 2021-02-08 08:34

I\'m trying to serialize my form data including file image field using jquery.form.js jQuery API. The API is helping me to serailze data fields including image

4条回答
  •  -上瘾入骨i
    2021-02-08 08:58

    You can use this way (from http://portfolio.planetjon.ca/2014/01/26/submit-file-input-via-ajax-jquery-easy-way/)

    $( '#my-form' )
      .submit( function( e ) {
        $.ajax( {
          url: 'http://host.com/action/',
          type: 'POST',
          data: new FormData( this ),
          processData: false,
          contentType: false
        } );
      } );
    

    it's more flexible and easy way

提交回复
热议问题