Hi i am working with an web application. in my webapp on the browser i am intiating an ajax call to update part of the page. I get the response as html from the server and i will insert the complete response into the div which displays it. I got a serious problem here. when server throws a page with 404 error then i should not display anything. I mean i should ignore that response. How this can be done? Thanks in advance. I am struggling with this from so long.

Recommended Answers

All 4 Replies

What's the code you are using. An AJAX call returns a status you can use.

The following is my code. please have a look at it.

function getHTTPObject() {
        if (typeof XMLHttpRequest != 'undefined') {
            return new XMLHttpRequest();
        }
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
        return false;
    }




    <script type="text/javascript">                      
            function getSearchStudents(){
                document.getElementById("noStudent").style.visibility = "hidden";
                var userString=document.getElementById("userString").value;
                var http=getHTTPObject();
                http.open("GET", "searchStudent.do?userString="+userString, true);              
                http.onreadystatechange = function() {
                    if (http.readyState == 4) {
                        document.getElementById("container").innerHTML=http.responseText;
                        if(http.responseText=="")
                            document.getElementById("noStudent").style.visibility = "visible";
                            if(http.responseText.length==2)
                                document.getElementById("noStudent").style.visibility = "visible";
                    }
                }
                http.send("");              
            }           
        </script> 
if (http.readyState == 4 && http.status == 200)

status respresents the HTTP response code, 200 is OK, it can also be 404.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.