13

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.

revo
  • 47,783
  • 14
  • 74
  • 117

2 Answers2

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 :

jQuery ownz

Florian Margaine
  • 58,730
  • 15
  • 91
  • 116
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
  • 4
    XMLHttpRequest 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