This time round I take the time to study each and every single steps in the pipeline in ajax request and what I'm going to do is... create yet another ajax framework of my own!
The very first code of ajax:
function createXMLHttpRequest() {The second:
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
try { return new XMLHttpRequest(); } catch(e) {}
alert("XMLHttpRequest not supported");
return null;
}
tryThe third:
{
var xhReq = createXMLHttpRequest();
xhReq.open("GET", "testajaxpage.aspx", true);
xhReq.setRequestHeader("ajax-auth", "anything");
xhReq.onreadystatechange = processResponse;
xhReq.send(null);
}
catch(e)
{
alert("Error In Request:" + e);
}
function processResponse() {I ran into an error while setting the setRequestHeader method, which it raise some "... nsIXMLHttpRequest.setRequestHeader error", and googled around then figured out that it had to be set only after opening the HttpRequest.
if (xhReq.readyState != 4) { return; }
var serverResponse = xhReq.responseText;
alert(serverResponse);
}
This link deserves the credits:
http://ajaxpatterns.org/XMLHttpRequest_Call
http://www.webmasterworld.com/forum91/4542.htm
regards,
choongseng
No comments:
Post a Comment