I have a weird issue that is probably simple here is the code
js file
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?
remove the <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.