ashx 数据返回得不到数据
一个aspx页面,一个ashx页面,,怎么把ashx文件中的context.Response.Write("OK");传到前台的label显示啊?谢谢
public void ProcessRequest (HttpContext context) {
string json = "OK";
context.Response.Write(json); 需要把这个到前台显示!!
}
前台脚本
<script type="text/javascript">
//
$(function () {
$("#txtContents").blur(function () {
$.post("Handler2.ashx", //要发送到的URL地址 以Post形式发送
{"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
function (data) //回调函数 参数data : 返回的json数据
{
l aert(data);
这里不弹出任何数据,貌似像是没返回任何数据一样
},
"json" //返回json类型数据
);
});
});
</script>
public void ProcessRequest (HttpContext context) {
string json = "OK";
context.Response.Write(json); 需要把这个到前台显示!!
}
前台脚本
<script type="text/javascript">
//
$(function () {
$("#txtContents").blur(function () {
$.post("Handler2.ashx", //要发送到的URL地址 以Post形式发送
{"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
function (data) //回调函数 参数data : 返回的json数据
{
l aert(data);
这里不弹出任何数据,貌似像是没返回任何数据一样
},
"json" //返回json类型数据
);
});
});
</script>
...全文
请发表友善的回复…
发表回复
jonny0220 2013-08-14
- 打赏
- 举报
$.ajax({
type: "post",
dataType: "text",
url: 'Handler2.ashx',
data: { "name": $("#txtContents").val(), "user_id": $("#TextBox1").val() },
success: function (msg) {
var htmls = "<li>" + msg + "</li>";
$("#ulContent").append(htmls);
}
});
Go 旅城通票 2013-08-14
- 打赏
- 举报
你返回的不是json格式的数据,但是你dataType指定为json了,按照json解析出错就不会执行success回调了
$.post("Handler2.ashx", //要发送到的URL地址 以Post形式发送
{"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
function (data) //回调函数 参数data : 返回的json数据
{
l aert(data);
这里不弹出任何数据,貌似像是没返回任何数据一样
},
"text" //去掉或者改为text或者html
);