AJAX Error

Status
Not open for further replies.

ziycon

New Member
I have the below link using the below ajax code and its throwing up the below error, can anyone help, I've been at it for ages and just can't figure it out, thanks for your help in advance.
Error: document.getElementById(containerid) is null
Source File: http://localhost/admin/useradmin.php?func=1#
Line: 69
Code:
<a onclick="getcontent('../ajax-111-ca+421/', 'span1'); return false;" href="#">
Code:
<script type="text/javascript" language="javascript">
    var loading_img = '/media/images/layout/loading.gif';
    var loading_msg = ' Loading...';
    var xmlhttp_obj = false;
    
    function xmlhttp()
    {
        if (window.XMLHttpRequest)
        { // if Mozilla, Safari etc
            xmlhttp_obj = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        { // if IE
            try
            {
                xmlhttp_obj = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    xmlhttp_obj = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
                {

                }
            }
        }
        else
        {
            xmlhttp_obj = false;
        }

        return xmlhttp_obj;
    }   //get content via GET

    function getcontent(url, containerid)
    {
        var xmlhttp_obj = xmlhttp();
        document.getElementById(containerid).innerHTML = '<img src="' + loading_img + '" />' + loading_msg;
        xmlhttp_obj.onreadystatechange=function()
        {
            loadpage(xmlhttp_obj, containerid);
        }
        xmlhttp_obj.open('GET', url, true);
        xmlhttp_obj.send(null);
        alert(url);
    }     

    function loadpage(xmlhttp_obj, containerid)
    {
        if ( xmlhttp_obj.readyState == 4 && xmlhttp_obj.status == 200 )
        {
            document.getElementById(containerid).innerHTML = xmlhttp_obj.responseText;
        }
    }
//]]>

</script>
 

louie

New Member
make sure the "span1" exists on the page as ID

Code:
<div id='span1'></div>
 

ziycon

New Member
I had it set wrong.I had the span set as:
Code:
<span1></span1>
When it should have been:
Code:
<span id="span1"></span>

Once again louie, thanks for your help.:)
 
Status
Not open for further replies.
Top