jquery异步回调判断ture false

前台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条件那判断感觉没起到效果。很头疼很急的问题 搞了一天了 都没弄出来哪的问题,希望帮忙快点解决,在线等。

隔江千里
浏览 431回答 11
11回答

慕码人8056858

直接返回链接不就行了么。

红颜莎娜

if(data == "True"){ 试试这样判断

牧羊人nacy

试过了 没用 唉 试过了 很多种啊

守着一只汪

贴主看了你的代码,你将数据提交到了一个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(); } } }

阿晨1998

if(data.result)

慕田峪9158850

就事论事 alert("返回"+data); 这里弹出什么内容?

DIEA

data=false 谢谢大家对我的指点,你们说的我都试过了,还是让它直接返回连接路径算啦,不过if那里判断不起作用,很纳闷。不知道哪的问题。

MMMHUHU

@lin_yue:  后台输出返回到data里的是字符串"false"而不是bool值,任何不为空的字符串都为真,当然进if里面了,详见我上面的回复。

慕无忌1623718

data里面是字符串,并且是"True"不是“true”,是“False”不是"false"
打开App,查看更多内容
随时随地看视频慕课网APP