proname = $("#txt_proName").val();
$.ajax({
type: "post",
url: "../FormHandler/ItemAllHandler.ashx",
data: { proname: proname, meth: "GetZhaobggJd" },
datatype: "text",
beforeSend: function() {
$('div#lbl_rpt_nozbgg').show('normal');
},
success: function(msg) {
alert(msg);//得不到值
},
complete: function() {
$('div#lbl_rpt_nozbgg').hide('normal');
}
});
//程序已经请求到后台这里了,设置断点得到异常 ProjectAndEntBll projectentbll = new ProjectAndEntBll();
DataSet ds = projectentbll.GetZhaobggJd();
if (ds != null)
{
context.Response.Write("true");
try
{
context.Response.End();//这里出异常
}
catch (Exception e) {
e.ToString();// e = {由于代码已经过优化或者本机框架位于调用堆栈之上,无法计算表达式的值。}
}
}
else
{
context.Response.Write("false");
context.Response.End();
}
如果不要context.Response.End();还是返回不到值。请问什么原因,怎么解决?
直接 response.write()
response.end();
juery参数
data:{"username":$("#txtname").val,"pwd":};
success:function(msg)
{
//调试下用alert typeof
}
alert(msg);//得不到值
},
这句走到了吗,没有alert还是alert null或是undefine?
建议以后AJAX都加上错误Calback
error: function(error) {
alert(error);//error信息
},
根本就不alert不弹出提示框,不知道为什么运行不到那句去
好明天去加上error: function(error) {
alert(error);//error信息
}这个
data: { proname: proname, meth: "GetZhaobggJd" },
改成这样试试:
if (ds != null)
{
Response.Clear();
Response.Write("true");
Response.End();
}
else
{
Response.Clear();
Response.Write("false");
Response.End();
}
C# codeif (ds!=null)
{
Response.Clear();
Response.Write("true");
Response.End();
}else
{
Response.Clear();
Response.Write("false");
Response.End();
}
[/Quote]
这样行了,但是有时还是获取不到,有时快,有时要等会才能获取到···
在END之前
那么就在$.ajax里讲异步的参数设置为false