jsp ajax iframe 异步提交,jquery – 如何使用iframe进行异步(AJAX)文件上传?

我会回答我的问题,我想我找到了解决方案。这些是我遵循的步骤,以实现目标:

>使表单的属性“target”指向“iframe”。

>使用普通的HTML请求(非Asynchronous / Ajax请求)提交表单。

>因为目标框架是iframe,整个页面不会被刷新 – 只是iframe。

>一旦iframe onload事件发生(使用Javascript捕获该事件),然后做你想要的,例如。您可以发送回列出最近上传的文件信息的请求。

最终代码如下所示:

File:

javascript:

$("iframe").load(function(){

// ok,now you know that the file is uploaded,you can do what you want,for example tell the user that the file is uploaded

alert("The file is uploaded");

// or you can has your own technique to display the uploaded file name + id ?

$.post('http://example.com/file-upload-service?do=getLastFile',null,function(attachment){

// add the last uploaded file,so the user can see the uploaded files

$("#ajaxResultTest").append("

" + attachment.name + ":" + attachment.id "
");

},'json');

});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值