FREE tutorial,solution,RSS Feeds on Operating Systems, Programming, Web Development, Applications, Databases, Networking, Hardware, Security, SEO Free Expertsforge Membership
Join us as Moderator
Submit Article to Expertsforge.com Submit Article My Expertsforge
 
RSS Feeds, Help Help RSS Feeds
bannertop
 

Ajax Tutorial: Request a web page containing URL parameters using AJAX

jawahar
11/13/2007 1:13:25 PM, Views: 1237
The following code can be used to make a request to an external web page by passing the URL parameters using AJAX

<html>
<head>
<title>Request External Web Page containing parameters using Ajax</title>
<script language="javascript" type="text/javascript">
function makeRequest(url, containerid, parameters) {
   http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      // set type accordingly to anticipated content type
      //http_request.overrideMimeType('text/xml');
      http_request.overrideMimeType('text/html');
    }
   } else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {}
    }
   }
   if (!http_request) {
    alert('Cannot create XMLHTTP instance');
    return false;
   }
   http_request.onreadystatechange = alertContents;
   http_request.open('GET', url + parameters, true);
   http_request.send(null);
}

function alertContents() {
   if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      result = http_request.responseText;
      document.getElementById('content').innerHTML = result;                  
    } else {
      alert('There was a problem with the request.');
    }
   }
}
</script>
</head>
<body>
<a href="javascript: makeRequest('http://www.expertsforge.com/fullstory.asp','content','?topicid=8');">Request Page</a>
<div id="content"></div>
</body>
</html>
Next Steps:
Add this Tutorial to:
Blink Blink del.icio.ous Del.icio.us Digg Digg
Fark Fark Furl Furl Google Google
Reddit Reddit Simpy Simpy Spurl Spurl
Technorati Technorati Windows Live Win Live Yahoo Yahoo
Rate Me!
Avg Visitor Rating: Average Visitor Rating is 3 out of 5
Number of Ratings : 6 Votes
Rate:
Send Private MessageSend Message
Signup / Login To View the Solution or Provide Comments
Post Comment/Solution
Comment:*
        (Link Rules) 
  Use : [bold] for <b>; [/bold] for </b>; [italic] for <i>; [/italic] for </i>; [code] & [/code] for code
 
Categories
Options
Ajax RSS Feed
Most Popular Tutorial
Most Popular Solution
No Records!
Top Rated
Top Rankers
Overall
1. jawahar (150)
2. francis_wong (50)
Yearly -2008
No Rankings!
Expertsforge Sponsors
bnrtop