By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,812 Members | 863 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,812 IT Pros & Developers. It's quick & easy.

How to import file inside javascript

P: 10
I want to import a file inside javascript..
for ex:<%@page import="java.util.ArrayList">
how i can import this file inside javascript
May 26 '10 #1
Share this Question
Share on Google+
4 Replies

Expert Mod 5K+
P: 8,639
if you have this file on the server, you can import its text content via AJAX. the text is then available through the .responseText property (given that the file is not processed on the server).
May 26 '10 #2

P: 10
Can u plz tell how we can import its text content via AJAX. i have no idea abt AJAX. Can't we import using javascript?
May 26 '10 #3

Expert Mod 5K+
P: 8,639
as I said, do a simple AJAX request.
Expand|Select|Wrap|Line Numbers
  1. // a very basic procedure, may not work in IE (kindly refer to the link on the bottom of this post for further information)
  2. var xhr = new XMLHttpRequest();
  3."POST", "your_file.txt", false);
  4. xhr.send();
  5. var txt = xhr.responseText;
  6. // now you have the content of "your_file.txt" in the txt variable
further introductions & tutorials you can find in our Offsite Links, AJAX section.
May 26 '10 #4

P: 10
ok thank you..
May 26 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.