我会回答我的问题,我想我找到了解决方案。这些是我遵循的步骤,以实现目标:
>使表单的属性“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');
});