Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get text from a txt file in the url

When I go to a url like this: http ://my.url.com/file.txt, the browser shows text.

I would like a simple javscript command that does the following:
1. go to the url
3. take the text that shows up on the screen
4. store it in a variable for further processing

so something like

var url = http: //my.url.com/file.txt;

//some code here that goes to the url

//some code that takes said info and does something like:

var fileInfo = ---content of file.txt---

Note that the info I seek from the txt file is in html tags

<p>Text I need in Variable</p>

Any assistance would be greatly appreciated!
Thank you!

like image 965
Aryeh K Avatar asked Sep 28 '16 21:09

Aryeh K


1 Answers

Make an AJAX call to the url. Here is using the jQuery library:

$.get( "http: //my.url.com/file.txt", function( data ) {
  var text = data;
});

To extract what you need from your text string in between the paragraph tags, try regex:

var pText = text.match(/<p>([^<]+)<\/p>/)[1];
like image 137
neal Avatar answered Sep 22 '22 04:09

neal