Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Response of Ajax not coming in div section

    hello... to all. Actually i am a beginner in Ajax .i was trying the following code but was unable to get the result as required.The result shuld be displayed in div sectionbt its is not working,result is that onclicking link it directs to corresponding link instead of remainng at that page.

    The code is as follows:
    index.html

    <html>
    <head>
    <title>Using Links With AJAX</title>
    <script type="text/javascript" language="javascript">
    var xmlhttp =false;

    function getXMLObject()
    {
    if (window.XMLHttpRequest)
    {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    return new XMLHttpRequest();

    }
    if (window.ActiveXObject)
    {
    // code for IE6, IE5
    return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
    }
    function makerequest(Page,ObjId)
    {
    xmlhttp = getXMLObject();
    if(xmlhttp == null)
    {
    alert ("Your browser does not support XMLHTTP!");
    return;
    }
    var obj = document.getElementById(ObjId);
    xmlhttp.open("Get",Page,true);
    xmlhttp.onreadystatechange =function()
    {
    if(xmlhttp.readyState == 4 and xmlhttp.status == 200)
    {
    obj.innerHTML = xmlhttp.responseText;
    }
    }
    xmlhttp.send(null);
    }
    </script>
    </head>
    <body onload="makerequest('content1.html','hint');">
    <div align="center">
    <h1>My Web Page</h1>
    <a href="content1.html" onclick="makerequest('content1.html','hint'); return false;">Page1</a>
    <a href="content2.html" onclick="makerequest('content2.html','hint'); return false;">Page2</a>
    <a href="content3.html" onclick="makerequest('content3.html','hint'); return false;">Page3</a>
    <div id="hint"></div>
    </div>
    </body>
    </html>
    and content1.html n content2.html n content3.html contains similar code as follows :

    <div style="width:770px; text-align:left;">
    <h1>Page 3</h1>
    This is Page No 3 .</div>
    Thanks

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    There is no and

    Code:
    if(xmlhttp.readyState == 4 and xmlhttp.status == 200)

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    New to the CF scene
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok . Thanks for ur quick help My Problem solved thanks a lot

    Hope to get further help from u in future


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •