|
Parsing xml response and update DOM object
Eventually,after receiving the response,the DOM object of the client html page will be updated. We do that in the updateDOM method:
function updateDOM() { if (oXMLRequest.readyState == 4) { if (oXMLRequest.status == 200) { strStatus = oXMLRequest.responseText;
var statusDiv = document.getElementById("status"); if (document.all) { statusDiv = document.all["status"]; }
if (strStatus == "Valid") { statusDiv.innerHTML = "<div style='color:green'> Valid user</div>"; } else if (strStatus == "Invalid") { statusDiv.innerHTML = "<div style='color:red'> Invalid user</div>"; } else if (strStatus == "Continue") { statusDiv.innerHTML = "<div style='color:green'> Continue..</div>"; } } }
The conditional line: oXMLRequest.readyState = 4 tells us that the XMLHttpRequest instance have just received the response message and the line oXMLRequest.status=200 which means that the service for response message has been done successfully.
The response message can be under text or xml format. In this method,parsing xml message is very simple: by getting the text value of the responseText property. Still there is another way to get content of response,by parsing value of the responseXML property. You could refer to the Ajax example for parsing xml for it.
|