jQuery upload file using jQuery's ajax method (without plugins)

后端 未结 5 1813
温柔的废话
温柔的废话 2021-02-01 23:41

At moment I want to implement picture upload without using any plug-ins.

My upload form looks like this

5条回答
  •  甜味超标
    2021-02-02 00:19

    jQuery ajax does not support file uploads and implementing this manually might be cumbersome. I would suggest you looking at the jQuery form plugin.

    Of course you could always check out the source code of the plugin to see how it is implemented if you don't want to include it (it uses a hidden iFrame as files cannot be uploaded with AJAX) but why doing it if you could use it directly :-)

    Here's an example how your code might look like:

    $(function() {
        $('#uploadform').ajaxForm();
    });
    

    also make the upload button a submit button:

    
    

提交回复
热议问题