jQuery Ajax文件上传

和自甴很熟 提交于 2020-10-06 09:28:06

问题:

Can I use the following jQuery code to perform file upload using POST method of an ajax request ? 我可以使用以下jQuery代码使用ajax请求的POST方法执行文件上传吗?

$.ajax({
    type: "POST",
    timeout: 50000,
    url: url,
    data: dataString,
    success: function (data) {
        alert('success');
        return false;
    }
});

If it is possible, do I need to fill data part? 如果有可能,我是否需要填写data部分? Is it the correct way? 这是正确的方法吗? I only POST the file to the server side. 我只将文件发布到服务器端。

I have been googling around, but what I found was a plugin while in my plan I do not want to use it. 我一直在搜索,但是我发现是一个插件,而在我的计划中我不想使用它。 At least for the moment. 至少目前是这样。


解决方案:

参考一: https://stackoom.com/question/9jYT/jQuery-Ajax文件上传
参考二: https://oldbug.net/q/9jYT/jQuery-Ajax-File-Upload
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!