我想用asp.net所以我不想回发,而上传页面上传文件。我怎样才能做到这一点,有没有什么办法使用Ajax来做到这一点。
I want to upload a file using asp.net so I do not want to post back the page while uploading . How can I do that and is there any way to do it using Ajax .
请在文件上传表单针对一个隐藏的iframe。
Make the file upload form target a hidden iframe.
<iframe name="UploadTarget" style="display:none"></iframe>
<form target="UploadTarget" action="postfile" method="post" enctype="multipart/form-data">
<input type="file" name="MyFile">
<input type="submit" name="submit" value="Send me a file">
</form>
最后一个诀窍是要添加到您的回复页面:
The final trick is to add to your response page:
<script type="text/javascript">parent.somecallbackfunction("Here is some data")</script>
要让你的父页面(包含隐藏的iframe的那个)知道,文件上传完成。
To let your parent page ( the one containing the hidden iframe) know that the the file upload has completed.