January 10, 2006

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>



 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()
+ ").";




just Developer note...


Anonymous said...

Thanx for your code! Works

Anonymous said...

How did this ever work?


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.