import from file in javascript
I have a html/javascript table/grid that I need to import data from a file, this is not possible without serverside. So I decides to have a FileEcho serve开发者_JS百科r that takes a file upload from the table/grid, the problem is I don't want to refresh the page afterwards, it's a multipart request, not an ajax request. Is it possible to up the file ajax style? how can this be done? any solution to my problem?
A popular way is to do the file upload in an iframe
(you can set the <form>
's target
attribute to the name
attribute of your iframe
)
You can attach an onload
event on the iframe
to find out when the data has been echoed from the server. From there, you can grab the contentDocument
attribute from the iframe
object in javascript (from there you could look at the innerHTML
content of the contentDocument.body
to see the data).
Just note that in IE, you have to use document.frames['frame_name'].document
instead of iframeObject.contentDocument
See these articles for more info:
- http://www.ajaxf1.com/tutorial/ajax-file-upload-tutorial.html
- http://www.openjs.com/articles/ajax/ajax_file_upload/
精彩评论