form提交给ashx以后,ashx在什么地方、怎么取值?
ashx的代码里有下面两个东西,这两个东西是干啥的?谁能深入浅出的解释一下吗?谢谢!
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
} public bool IsReusable
{
get
{
return false;
}
}
ashx的代码里有下面两个东西,这两个东西是干啥的?谁能深入浅出的解释一下吗?谢谢!
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Response.Write("Hello World");
} public bool IsReusable
{
get
{
return false;
}
}
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
context.Request["Id"] --取值页面传递Id
--业务处理
context.Response.Write("Hello World");--返回值
} public bool IsReusable
{
get
{
return false;
}
}
{
//string aa=context.Request.QueryString["txtName"];
string par=context.Request.Form["txtName"];
context.Response.ContentType = "text/plain";
context.Response.Write(par);
}
public bool IsReusable
{
get
{
return false;
}
}
注:要想详细了解这两个东西请参考MSDN
html <form id="form_PostTopicReply">
<textarea name="ContentsOfTopicReply" cols="60" rows="5"></textarea>
<div>
<input type="submit" id="PostTopicReply" value="回复帖子" />
<input type="reset" value="重填" />
</div>
</form>
ajax提交
function PostTopicReply()
{
$.ajax({
type:"post",
url:"PostTopicReply.ashx",
data:$('#form_PostTopicReply').serialize(),
success:function(msg){
}
});
}ashx文件
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain"; //这个取不到ContentsOfTopicReply的值
string ContentsOfTopicReply = context.Request.Form["ContentsOfTopicReply"]; context.Response.Write("Hello World");
} public bool IsReusable
{
get
{
return false;
}
}
定义 HTTP 处理程序 (.ashx) 文件的属性和编译选项
IsReusable属性
这个属性默认为false(Visual studio提供的模板默认将其设置为false)
如果设置为true,能提高性能,但要注意线程之间安全性问题
如果设置为false,则线程是安全的
xmlDom.Open("get",strURL , true);
xmlDom.onreadystatechange = fnRun1;
xmlDom.Send(xmlDom);string username = context.Request.QueryString["username"];
酱紫试一下
form是可以提交给ashx的 能就我这个问题具体分析一下吗
就是打断点看到取到的值为null
你的button的id和js的函数名一样了,PostTopicReply就这个名字。
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="Aspx_Cpzl_test" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script src="../../Js/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function PostTopicReply()
{//alert();
$.ajax({
type:"post",
url:"tHandler.ashx",
data:$('#form_PostTopicReply').serialize(),
success:function(msg){
alert(msg);
}
});
//$.post('tHandler.ashx', $('#form_PostTopicReply').serialize(), function(data){$('#div_change_text').html(data);});
}
</script>
</head>
<body>
<form id="form_PostTopicReply">
<div id="div_change_text"></div>
<textarea name="ContentsOfTopicReply" cols="60" rows="5"></textarea>
<div>
<input type="button" id="btn_PostTopicReply" value="回复帖子" onclick="javascript:PostTopicReply();"/>
<input type="reset" value="重填" />
</div>
</form>
</body>
</html>
按照你这个写法,改掉id以后,还是和之前一样的效果,取到的值也是null。
<input type="submit" id="PostTopicReply" name="PostTopicReply" value="回复帖子" />ashx就可以用下面的方法来取值.
string xxx=context.Request.Form["PostTopicReply"];
我现在碰到个问题 我用firebug查看页面元素 里面根本就看不到这个form 但是右键查看源代码里是能看到这个form的 这是什么问题 搞死人了
我现在碰到个问题 我用firebug查看页面元素 里面根本就看不到这个form 但是右键查看源代码里是能看到这个form的 这是什么问题 搞死人了
定义 HTTP 处理程序 (.ashx) 文件的属性和编译选项
IsReusable属性
这个属性默认为false(Visual studio提供的模板默认将其设置为false)
如果设置为true,能提高性能,但要注意线程之间安全性问题
如果设置为false,则线程是安全的
xmlDom.Open("get",strURL , true);
xmlDom.onreadystatechange = fnRun1;
xmlDom.Send(xmlDom);string username = context.Request.QueryString["username"];
用firebug查看页面元素居然看不到里面的这个form。xhbmj(鬼吹灯),你的例子里面实际上是没有页面默认的这个form的,你加上去再试试看是什么情况。
我上面发的代码是经过调试的,request.form可以取到值。既然你要用ajax提交表单,那么就去掉runat=server
请问有什么办法解决么?
如下的是允许的:
<form id=form1>
....//html控件
</form>
<form id=form2>
....//html控件
</form>
如下的是不允许的:
<form id=form1><form id=form2></form></form>