Loading web page in a div using Ajax

Using Iframe, it is very easy to load web page in your page. But if you want to load page in a div, Ajax can be helpful.

    <script type="text/javascript">
    function makeRequest(url) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                catch (e) {}

        if (!httpRequest) {
            alert('Giving up 😦 Cannot create an XMLHTTP instance');
            return false;
        httpRequest.onreadystatechange = function() { state_Change(httpRequest); };
        httpRequest.open('GET', url, true);


    function state_Change(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
                var s = httpRequest.responseText;
                s = s.slice(s.indexOf("<fo" + "rm"));
                s = s.replace("</body>","");
                s = s.replace("</html>","");
                s = s.replace(/<form/ig,"<formdisabled");
            } else {
                alert("Problem retrieving data:" + httpRequest.statusText);


In the design mode,
    <form id="form1" runat="server">
        <div id="ext">
        <input type="button" onclick="makeRequest('http://amar-desh.net/');" />

One thought on “Loading web page in a div using Ajax

  1. Hello ,Please can u tell me or provide the code that how can i load a page in div using Ajax in asp.net

    Waiting for your reply,

    Thank you

    Amit Habu

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s