一个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>JSON脚本
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>JSON脚本
// and remember the jqxhr object for this request
var jqxhr = $.post("example.php", function() {
alert("success");
})
.done(function() { alert("second success"); })
.fail(function() { alert("error"); })
.always(function() { alert("finished"); });看看是不是进入fail里面了。
{"name": $("#txtContents").attr("value"), "user_id": $("#TextBox1").attr("value") }, //发送的Json数据 _name 对应Home/getJsonData方法中的参数名字
function (data) //回调函数 参数data : 返回的json数据
{
l aert(data);
这里不弹出任何数据,貌似像是没返回任何数据一样
},
"text" //去掉或者改为text或者html
);