Early AJAX, I am having no luck with this.
I am not getting any errors, although.
But none of the "document.getElementById"s are printing out either.
Could someone show me the path.
Default.aspx<head><script type="text/javascript">
function getajax() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
document.getElementById("<%=Label1.ClientID%>") = "Windows";
}
else {
throw new Error("Ajax is not supported by this browser");
document.getElementById("<%=Label2.ClientID%>") = "Ajax is not supported by this browser";
}
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
//executes on success
document.getElementById("<%=Label3.ClientID%>") = "Success";
xhr.open("POST", Default.aspx / GetValue);
xhr.send();
}
else {
//executes on error
document.getElementById("<%=Label2.ClientID%>") = "Error";
}
}
}
}</script></head><body><form><asp:Label ID="Label1" runat="server" Text=""></asp:Label><asp:Label ID="Label2" runat="server" Text=""></asp:Label><asp:Label ID="Label3" runat="server" Text=""></asp:Label><asp:Button ID="Button1" runat="server" Text="Execute" OnClick="Button1_Click" /></form></body>
Default.aspx.cs
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Javascript", "Javascript:getajax();", true);
}