Loading Content Of Page Using AJAX

You can load the contents of a page inside an HTML layer element using AJAX with this function. The url parameter can accept querystrings of dynamic pages.

?View Code JAVASCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function get_content(url, div_id) {
  var req;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
 
  if (req != undefined) {
    req.onreadystatechange = function() {
      if (req.readyState == 4) { // only if req is "loaded"
        if (req.status == 200) { // only if "OK"
          document.getElementById(div_id).innerHTML = req.responseText;
	}
      }
    };
 
    req.open("GET", url, true);
    req.send("");
  }
}

Donations appreciated. Every little $ helps. Or click Google +1

Related Posts with Thumbnails

tags:

One Response to “Loading Content Of Page Using AJAX”

  1. 1
    News Loading Content Of Page Using AJAX | Web 2.0 Designer Says:

    [...] See the original post here: Loading Content Of Page Using AJAX [...]

Leave a Reply

Spam protection by WP Captcha-Free