revo
revo

Reputation: 48711

Get file contents in java script

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.

Upvotes: 13

Views: 64126

Answers (2)

balaphp
balaphp

Reputation: 1326

you can get the contents from that URL by using jQuery

$.get('website_url', function(data) {
     alert(data);
});

Upvotes: 17

Florian Margaine
Florian Margaine

Reputation: 60747

You can use XMLHttpRequest in Javascript to fetch datas from an external URL. Here is a good resource : http://www.w3schools.com/ajax/default.asp (I usually don't recommend them, but the AJAX tutorial is really good).

Also, this had to be there :

jQuery ownz

Upvotes: 66

Related Questions