Problema de AJAX / ASP.NET

I have a weird issue that is probably simple here is the code

archivo js

    function visitorAction(firstnm,lastnm)
{

    var xmlhttp;


    xmlhttp=new XMLHttpRequest();


   xmlhttp.onreadystatechange=function()
   {
    if(xmlhttp.readyState==4 && xmlhttp.status==200)
        {
           document.getElementById('placeholder').innerHTML=xmlhttp.responseText;

        }

   }

  xmlhttp.open("GET", "Handler1.ashx?firstname="+firstnm+"&lastname="+lastnm, true);
   xmlhttp.send();
}

My webform -yes the js file is being correctly called

 <form id="form1" runat="server">
    <div>
    <table>
            <tbody>
                <tr>
                    <td>First Name</td>
                    <td><asp:TextBox ID="firstnameTextBox" runat="server"></asp:TextBox></td>
                    <td><asp:RequiredFieldValidator 
                    ID="RequiredFieldValidator1" 
                    runat="server" 
                    ErrorMessage="Fill in your first name"
                    ControlToValidate="firstnameTextBox"></asp:RequiredFieldValidator></td>
                </tr>
                <tr>
                    <td>Last Name</td>
                    <td><asp:TextBox ID="lastnameTextBox" runat="server"></asp:TextBox></td>
                    <td><asp:RequiredFieldValidator 
                        ID="RequiredFieldValidator2" 
                        runat="server" 
                        ErrorMessage="Fill in your last name"
                        ControlToValidate="lastnameTextBox"></asp:RequiredFieldValidator></td>
                </tr>
            </tbody>
        </table>
        <asp:LinkButton ID="LinkButton1" runat="server" OnClientClick="return visitorAction('firstnameTextBox','lastnameTextBox');">Login</asp:LinkButton>
        <asp:LinkButton ID="LinkButton2" runat="server" PostBackUrl="Registration.aspx">Register</asp:LinkButton>
    </div>
    <div id = "placeholder">

    </div>

my handler

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CSC515_Project5_GREGORY
{

    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {

            context.Response.ContentType = "text/html";
            context.Response.Write("<html>");
            context.Response.Output.WriteLine("hello");
            context.Response.Write("</html>");

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

my issue is that the function does not work when I fill in anything in my input fields and click "login". It should just return "hello" for testing but nothing happens and no console errors occur. When I click "login" without filling in any field it does what it is supposed to do. what gives?

preguntado el 10 de marzo de 12 a las 07:03

small off topic use docs.jquery.com/API/1.1/AJAX for ajax call it add to your code cross browserx functionality . -

1 Respuestas

eliminar el <html> part in the handler.context.Response.Output.WriteLine("hello"); is enough for you. see this site for more information about how to use ajax in asp.net applications.

respondido 10 mar '12, 08:03

no dice :/ like i said in the question it works when I don't have data entered. - user975044

poner return false; after the ` xmlhttp.send();`. - Chamika Sandamal

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.