Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
The statement below does nothing when the Button1 is pressed none of the innerHtml statements are enacted. Where am I going wrong?

JavaScript
<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%>").innerHTML  = "Windows";
            }
            else {
                throw new Error("Ajax is not supported by this browser");
                document.getElementById("<%=Label2.ClientID%>").innerHTML = "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%>").innerHTML = "Success";
                        xhr.open("POST", Default.aspx / GetValue);
                        xhr.send();
                    }
                    else {
                        //executes on error
                        document.getElementById("<%=Label2.ClientID%>").innerHTML = "Error";
                    }
                }
            }
        }
    </script>
Posted
Comments
rmksiva 5-Nov-14 23:11pm    
did you have any browser errors at the time of running ?
Teledextri 5-Nov-14 23:12pm    
No errors or output
Laiju k 5-Nov-14 23:26pm    
give source of Button1
Sinisa Hajnal 6-Nov-14 2:28am    
Try removing readyState check and status check just to see what else comes your way. (that is, put readyState and statuses in your label and click the button to see what is going on.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900