[英]AJAX / ASP.NET issue
我有一個奇怪的問題,這里的代碼可能很簡單
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();
}
我的webform - 是的,正確調用了js文件
<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>
我的經紀人
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;
}
}
}
}
我的問題是,當我在輸入字段中填寫任何內容並單擊“登錄”時,該功能不起作用。 它應該返回“hello”進行測試,但沒有任何反應,也沒有出現控制台錯誤。 當我單擊“登錄”而不填寫任何字段時,它會執行它應該執行的操作。 是什么賦予了?
刪除處理程序中的<html>
部分。 context.Response.Output.WriteLine("hello");
對你來說已經足夠了。 有關如何在asp.net應用程序中使用ajax的更多信息,請訪問此站點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.