How do I load the contents of a text file into a javascript variable?

后端 未结 9 804
南笙
南笙 2020-11-22 07:22

I have a text file in the root of my web app http://localhost/foo.txt and I\'d like to load it into a variable in javascript.. in groovy I would do this:

         


        
9条回答
  •  [愿得一人]
    2020-11-22 08:11

    If your input was structured as XML, you could use the importXML function. (More info here at quirksmode).

    If it isn't XML, and there isn't an equivalent function for importing plain text, then you could open it in a hidden iframe and then read the contents from there.

提交回复
热议问题