Replacing DIV Contents

Discussion in 'JavaScript' started by ehime, Oct 28, 2008.

  1. #1
    For some reason this keeps opening in its own window, not in
    its specified DIV. Any Ideas?

    HTML
    
    <a href="layers/main.html" onclick="loadXMLDoc(req);return false">main</a>
    ...
    <div name="bodyFRAME" id="iContent"></div>
    
    Code (markup):
    JS
    
    function loadXMLDoc(url) 
    {
        // branch for native XMLHttpRequest object
        if (window.XMLHttpRequest) {
            req = new XMLHttpRequest();
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send(null);
        // branch for IE/Windows ActiveX version
        } else if (window.ActiveXObject) {
            req = new ActiveXObject("Microsoft.XMLHTTP");
            if (req) {
                req.onreadystatechange = processReqChange;
                req.open("GET", url, true);
                req.send();
            }
        }
    }
    function processReqChange() 
    {
        // only if req shows "complete"
        if (req.readyState == 4) {
            // only if "OK"
            if (req.status == 200) {
    	if(document.getElementById) {
            document.getElementById("iContent").innerHTML = req.responseText;
    					}
            } else {
           alert("There was a problem retrieving the XML data:\n" + req.statusText);
    	        }
    	    }
    	}
    
    Code (markup):

     
    ehime, Oct 28, 2008 IP
  2. lp1051

    lp1051 Well-Known Member

    Messages:
    163
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    108
    #2
    Do you mean, it opens the page main.html?? If so, then there has to be error in your javascript code. In function loadXMLDoc() as it doesn't come to return false;
    From the example - is the req variable really some URL?? Is it defined??
     
    lp1051, Oct 28, 2008 IP