Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
3.50/5 (4 votes)
See more:
I am using a input button like this:
<input id="btnDoAjaxCall" type="button" value="Check Availability" onclick="return btnDoAjaxCall_onclick()" />
but when i click this button it does not work.

i also used master page in the project.
this is my javascript code:
<script language="javascript" type="text/javascript">
    function btnDoAjaxCall_onclick() {
        var xmlhttp;
        if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
        }
        else {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("showAvailability").innerHTML = xmlhttp.responseText;
            }
        }
        var str = document.getElementById("txtEmail").value;
        //sending request to handler page
        xmlhttp.open("GET", "Handler.ashx?uname=" + str, true);
        xmlhttp.send();
    }
    </script>


I write this code in head of the master page. i also check this code to placed in the
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">

but it does not work. Please help how can i solve this.
This code is working in my previous project where i not used master page. But after using master page it does not work. Please help me for do this.
Thanks in advance


can any one tell me where i can write this javascript code. txtEmail textbox and showAvailability div is my another page.
Posted
Updated 29-May-11 22:45pm
v3
Comments
Steven.Pinto2000 30-May-11 9:20am    
Can you also show the aspx page

1 solution

The code looks right, but as you say there is a problem somewhere.

I think you should get in the habit of debugging. You can debug Javascript using Firebug add on in Firefox. Check the steps one by one, does the request hit the Handler.ashx page? If so does it return a proper response?

Also use jQuery or Prototype libraries for Ajax calls, using plain XmlHttpRequest is not encouraged (too much code for simple stuff plus few more issues).

Alternatively you have to send your whole code to us so.
 
Share this answer
 

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