How to upload an image through jQuery?

前端 未结 6 829
悲&欢浪女
悲&欢浪女 2020-12-09 12:11

For past few days i have been struggling to submit a form with jQuery and AJAX. The problem i\'m facing is to upload the image in the form field.

My form is somethin

6条回答
  •  孤街浪徒
    2020-12-09 13:01

    serialize() method not able to post file data.

    For sending file using ajax use FormData instead of serializing

    HTML5 introduces FormData to allow developers to build forms objects dynamically, and then to send this form object via AJAX.

    your Html

    AJAX call

    
    
    

    upload_image.php

    print_r($_FILES) //check you get file data or not
    

    Try this way.Hope it will help you

提交回复
热议问题