我正在使用javascript异步发送一个名称作为查询字符串,该名称将保存在文件中,由于某些原因我不想使用jquery。但是代码不起作用。请帮忙。
名称Test.aspx
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Name: "></asp:Label>
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
<asp :Button ID="btnSubmit" runat="server" OnClientClick="AJAX()" Text="Submit" />
</div>
</form>
<script>
function AJAX()
{
var http;
if (window.XMLHttpRequest)
{
http = new XMLHttpRequest();
}
http.open("GET", "AJAXHandler.aspx?name=marium", true);
http.send(null);
}
</script>
</body>
</html>
我的处理程序文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace AJAXNewBostonPrac1
{
public partial class AJAXHandler : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileStream fs = new FileStream(@"c:/ajax.txt", FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.WriteLine(Request.QueryString["name"].ToString());
sw.Close();
}
}
}