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.
Asked
Active
Viewed 6.4k times
13

revo
- 47,783
- 14
- 74
- 117
2 Answers
66
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 :

Florian Margaine
- 58,730
- 15
- 91
- 116
-
1The link is broken. It would be nice if you can write the solution script in your answer. – milkovsky Aug 24 '20 at 09:41
17
you can get the contents from that URL by using jQuery
$.get('website_url', function(data) {
alert(data);
});

balaphp
- 1,306
- 5
- 20
- 40
-
4XMLHttpRequest cannot load http://*****. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://*****' is therefore not allowed access. – BZC Jul 09 '14 at 11:00