"Without a web framework," William I. writes, "developing AJAX-based code can be a bit tricky. Mostly, because of the way X (XmlHttpRequest) deals with A (Asynchronous): you have to 'listen' to the onreadystatechange and act when the readyState is 4."

"Of course, most folks deal with this using a simple if (readyState == 4) statement. Some coders... well... they do this."

onreadystatechange = function(){

    switch(httpReq.readyState){
        case 0: if(httpReq.readyState == 0){
            break;
        }
        case 1: if(httpReq.readyState == 1){
            break;
        }
        case 2: if(httpReq.readyState == 2){
            break;
        }
        case 3: if(httpReq.readyState == 3){
            break;
        }
        case 4: if(httpReq.readyState == 4){
            if(httpReq.status == 200){
                var val = httpReq.responseText;

                alert(httpReq.responseText)
                dataInsert(val);
                break;
            }
            else{
                alert("Error "+httpReq.status);
                break;
            }
        }
    }
};

"I guess this way it realy makes sure the switch is functioning."

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!