How to import file inside javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaaash
    New Member
    • May 2010
    • 10

    #1

    How to import file inside javascript

    Hi.
    I want to import a file inside javascript..
    for ex:<%@page import="java.ut il.ArrayList">
    how i can import this file inside javascript
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    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).

    Comment

    • aaaash
      New Member
      • May 2010
      • 10

      #3
      Originally posted by Dormilich
      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).
      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?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        as I said, do a simple AJAX request.
        Code:
        // a very basic procedure, may not work in IE (kindly refer to the link on the bottom of this post for further information)
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "your_file.txt", false);
        xhr.send();
        var txt = xhr.responseText;
        // 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.

        Comment

        • aaaash
          New Member
          • May 2010
          • 10

          #5
          Originally posted by Dormilich
          as I said, do a simple AJAX request.
          Code:
          // a very basic procedure, may not work in IE (kindly refer to the link on the bottom of this post for further information)
          var xhr = new XMLHttpRequest();
          xhr.open("POST", "your_file.txt", false);
          xhr.send();
          var txt = xhr.responseText;
          // 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.
          ok thank you..

          Comment

          Working...