0

我正在使用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();
}
}
}
4

1 回答 1

0

哦,我忘了写 return false;AJAX() 函数和函数调用中的语句也像这样: OnClientClick="return AJAX()"

于 2013-07-04T05:17:10.057 回答