Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show / hide layer function causing error but working 1

Status
Not open for further replies.

snowboardr

Programmer
Joined
Feb 22, 2002
Messages
1,401
Location
PH
This function is causing an error, but it still shows layer etc... I am using it for ajax loading image... the error occurs inside the createboject / ajax when i take the hideLayer part out it doesn't error, and the layer stays visible, however when its in there i get this error in firefox:


Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: :: getLoadMAINHTMLHttpResponse :: line 72" data: no]
Source File: Line: 72


In Internet explorer i get unspecified error.


I take it from the error it has something to do with the netscape code because of "NS"



Code:
var LoadMAINHTMLHttp = null;
function LoadMAINHtml(strCategoryName) {
	showLayer('LoadingImage2');
    LoadMAINHTMLHttp = createRequestObject();
    var url3="/ajax/main_topics.asp?cat_name=" + strCategoryName
    LoadMAINHTMLHttp.open('GET', url3, true);
    LoadMAINHTMLHttp.onreadystatechange = getLoadMAINHTMLHttpResponse;
    LoadMAINHTMLHttp.send('');
}


function getLoadMAINHTMLHttpResponse() {
    if (LoadMAINHTMLHttp != null)
        if (LoadMAINHTMLHttp.readyState == 4)
				hideLayer('LoadingImage2');
            if (LoadMAINHTMLHttp.status == 200)
                document.getElementById('topics').innerHTML = LoadMAINHTMLHttp.responseText;	
				
}

Code:
  function showLayer(layerName)
        {
            if (document.getElementById) // Netscape 6 and IE 5+
            {
                var targetElement = document.getElementById(layerName);
                targetElement.style.visibility = 'visible';
            }
        }


        function hideLayer(layerName)
        {
            if (document.getElementById) 
            {
                var targetElement = document.getElementById(layerName);
                targetElement.style.visibility = 'hidden';
            }
        }
 
Your indentation in the getLoadMAINHTMLHttpResponse implies you want the "if (LoadMAINHTMLHttp.status == 200)" test be run only if the "if (LoadMAINHTMLHttp.readyState == 4)" test passes.

Is this the case, or is your indentation simply wrong?

If it is the case, you'd need to add some braces in.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks,

it works if I put the show layer js below


if (LoadMAINHTMLHttp.status == 200)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top