前台JS
<!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> <title>New Document </title><script type="text/javascript" src="js/jquery-1.4.1.js"></script><script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript"> function aj(){ alert("fsdf"); var openId=null;//'0E0C36C83EA68C8058F9ACE3CBFDDCEE'; $.post( "Handle.aspx", { openId:openId}, function (data){ alert("返回"+data); if(data){ alert("0返回"+data); window.location.href="http://cloud.suridea.cn/Index.aspx"; }else{ alert("1返回aa"+data); window.location.href="http://cloud.suridea.cn/user/register.aspx?openid="+openId; } });
} </script>
</head><body><span id="wb_connect_btn"></span> <input id="Button1" onclick="aj();" type="button" value="button" />
</body></html>
后台cs
protected void Page_Load(object sender, EventArgs e) {
if (HttpContext.Current.Request["openId"] != null) {
Suridea.CloudService.Model.User user = new Suridea.CloudService.Model.User(); user.Remark = Request["openId"].ToString(); IList<User> u = userService.FindUsers(user); bool result=false; if (u.Count != 0) { result = true;
} else { result = false; } HttpContext.Current.Response.ContentType = "text/plain"; HttpContext.Current.Response.CacheControl = "no-cache"; HttpContext.Current.Response.Write(result); HttpContext.Current.Response.Flush();
} }
以上为我js代码 很头疼啊 处理代码
我代码异步回调成功了 返回data有时候明明是false却还是跑到if里面,然后我把data改为返回字符串还是if条件那判断感觉没起到效果。很头疼很急的问题 搞了一天了 都没弄出来哪的问题,希望帮忙快点解决,在线等。
11 回答
守着一只汪
TA贡献1872条经验 获得超3个赞
贴主看了你的代码,你将数据提交到了一个aspx文件来处理,为了以绝后患!!!
我教你一个方法。
新建一个"一般处理程序”。后缀是ashx文件。
写入以下代码:
public void ProcessRequest(HttpContext context) { if (context.Request["openId"] != null) { if (context.Request["openId"] != null) { Suridea.CloudService.Model.User user = new Suridea.CloudService.Model.User(); user.Remark = context.Request["openId"].ToString(); IList<User> u = userService.FindUsers(user); bool result = false; if (u.Count != 0) { result = true; } else { result = false; } context.Response.ContentType = "text/plain"; context.Response.CacheControl = "no-cache"; context.Response.Write(result); context.Response.Flush(); } } }
MMMHUHU
TA贡献1834条经验 获得超8个赞
@lin_yue:
后台输出返回到data里的是字符串"false"而不是bool值,任何不为空的字符串都为真,当然进if里面了,详见我上面的回复。
- 11 回答
- 0 关注
- 468 浏览
添加回答
举报
0/150
提交
取消