ajax文件上传

2021-12-24 00:00:00 file-upload upload php javascript ajax

我想使用 Ajax 和 php 上传文件.我有一个带有 标签的表单.我希望当用户浏览文件并单击提交时,该文件无需刷新即可上传.我该怎么做?是否刷新无关紧要,但我想借助 ajax 上传文件.

I want to upload a file using Ajax and php. I have a form with <input type="file"> tag. I want when user browses a file and clicks on submit, the file to be uploaded without a refresh. How should I do this ? It does't matter if refresh occur but i want to upload file with help of ajax.

推荐答案

  • 使用隐藏的 iframe 并将表单的目标设置为该 iframe 的名称.这样,提交表单时,只会刷新 iframe.
  • 为 iframe 的加载事件注册一个事件处理程序以解析响应.
  • 关于我的博文的更多细节:http://blog.manki.in/2011/08/ajax-fie-upload.html

    More details on my blog post: http://blog.manki.in/2011/08/ajax-fie-upload.html

相关文章