JavaScript : HTTP Get

I would like to grab http://www.yahoo.com/ website by JavaScript. I found the JavaScript library,
"request.js" (XmlHttpRequest Wrapper) from http://adamv.com/dev/. Demo here!



This is my JavaScript example to grab web page from yahoo.com

<script src="request.js"></script>

<span id="HttpContents">NO DATA</span>

<script>

Http.get({

 url: "http://www.yahoo.com/",

 callback: getHttpContents,

 cache: Http.Cache.GetNoCache

}, [HttpContents]);



function getHttpContents(result,HttpContents){

 if (result.status==Http.Status.OK){

  HttpContents.innerHTML = result.responseText;

 } else {

  HttpContents.innerHTML = "An error occurred (" + result.status.toString()
+ ").";

 }

}

</script>




just Developer note...

Comments

Anonymous said…
Thanx for your code! Works
Anonymous said…
How did this ever work?

http://adamv.com/dev/javascript/http_request

url
The URL to request. Required. Note that due to security restrictions, the URL must point to the same server as the current page. You cannot use XmlHttpRequest to retrieve results from external servers directly.

According to the api and just copy/pasting your code it fails.

Popular posts from this blog

3G Bandwidth bonding solutions

docker - could not read CA certificate