After that, just call uploadAndLoad ; in your code. This isn't possible with vanilla javascript, you'd need flash or some other approach to do what you want. The file has to be first uploaded to the server. I think I will do a simple ajax form to upload the file and then get the content with php before deleting the file and printing it, can't think of another solution.
As you say there's no other way than taking the text on the round trip to the server and back. However to ease the pain a bit you can fully automate this:. Attribution is due. I learned this technique from AJAX file upload tutorial. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. How to read a txt from an Open File dialog and load the content in a textarea with javascript jquery? Ask Question. Asked 11 years, 8 months ago. Active 2 years, 6 months ago. U and me U and me 5 5 silver badges 13 13 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.
New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions. Question feed. I used to have a filter in here using the name extension, but in the demo this has been commented out. The file name resides within the "href" attribute separated from the destination file by a question mark. This makes it a parameter passed into the destination Javascript, when you click the file name hyperlink shown in the browser.
It shows the creation of an array called UrlParameter , being filled with the complete contents of the URL as shown in the address bar in Internet Explorer. This contents is split by the question mark character and divided over the subsequent array elements. The name of the selected file is directly behind the question mark, so it ends up in the second array element, from where it can be used. In this example it's only shown in the browser, but it can't be too hard to think of other uses.
In my application, the XML-data was loaded from the file and interpreted to be shown in the browser. I had some trouble getting in the backslash character as separator in the path variable, since this acts as escape character in JavaScript, telling the interpreter that the subsequent character has to be taken literally and not having a special function. So in order to output one backslash you'd have to enter two: the first one telling the interpreter that the second one has to be output.
When I tried this, nothing appeared.
0コメント