html页面
- HTML code
<form id="submitForm" action="leave.ashx" method="post">您的真实姓名:<input type="text" id="realName" name="realName" /><input type="submit" value="测试" /></form> <script>function leave(des){ //这里测试用只有弹框,实质上需要做其他html页面上的处理 alert(des);}</script>
leave处理页面
- C# code
<%@ WebHandler Language="C#" Class="leave" %>using System;using System.Web;using System.Data.OleDb;using System.Data;using System.Web.SessionState;using System.Text;public class leave : IHttpHandler, IReadOnlySessionState{ public void ProcessRequest(HttpContext hc) { hc.Response.ContentType = "text/html"; hc.Response.Charset = "UTF-8"; string realName = hc.Request.Form["realName"].ToString(); string str = "提交成功!"; hc.Response.Write("<script language='javascript' type='text/javascript'>leave('" + str + "');</script>"); hc.Response.End(); } public bool IsReusable { get { return false; } }}
想实现的目的是当用提交用户真实姓名时,leave处理表单内容,然后返回相应的信息。我是这种思路,但是只要一提交就会打开leave.ashx页面,请高手帮助。怎么才能实现这种效果
------解决方案--------------------------------------------------------
ajax请求到该页面吧,不会弹出页面来的
------解决方案--------------------------------------------------------
楼主,先在页面上定义一个iframe,src指向你的ashx,然后把iframe隐藏了。给你的iframe一个id和name,这里我假设是iframe1。
然后,你的表单提交地址删掉,把target的属性设置为你的iframe的id,这样你再试试点击你的提交按钮,是不是有效果了