Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get file contents in java script

Tags:

javascript

I've a URL that its contents are also JavaScript codes, I want to get the contents of this URL via JavaScript something like to file_get_contents() in PHP and show them to the user using the alert() function.

like image 995
revo Avatar asked Nov 12 '11 09:11

revo


People also ask

How do you read the contents of a file in JavaScript?

To read a file, use FileReader , which enables you to read the content of a File object into memory. You can instruct FileReader to read a file as an array buffer, a data URL, or text. // Check if the file is an image.

What is FileReader in JavaScript?

The FileReader object lets web applications asynchronously read the contents of files (or raw data buffers) stored on the user's computer, using File or Blob objects to specify the file or data to read.

Can JavaScript access local files?

Web browsers (and JavaScript) can only access local files with user permission. To standardize file access from the browser, the W3C published the HTML5 File API in 2014. It defines how to access and upload local files with file objects in web applications.


1 Answers

you can get the contents from that URL by using jQuery

$.get('website_url', function(data) {
     alert(data);
});
like image 118
balaphp Avatar answered Nov 15 '22 22:11

balaphp