为了账号安全,请及时绑定邮箱和手机立即绑定

jquery异步回调判断ture false

jquery异步回调判断ture false

隔江千里 2018-12-07 10:48:00
前台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 回答

?
慕码人8056858

TA贡献1803条经验 获得超6个赞

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

查看完整回答
反对 回复 2019-01-21
?
红颜莎娜

TA贡献1842条经验 获得超12个赞

 if(data == "True"){

试试这样判断

查看完整回答
反对 回复 2019-01-21
?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

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

查看完整回答
反对 回复 2019-01-21
?
守着一只汪

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();


                }




            }
        }
查看完整回答
反对 回复 2019-01-21
?
阿晨1998

TA贡献2037条经验 获得超6个赞

if(data.result)

查看完整回答
反对 回复 2019-01-21
?
慕田峪9158850

TA贡献1794条经验 获得超7个赞

就事论事

alert("返回"+data);

这里弹出什么内容?

查看完整回答
反对 回复 2019-01-21
?
DIEA

TA贡献1820条经验 获得超2个赞

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

查看完整回答
反对 回复 2019-01-21
?
MMMHUHU

TA贡献1834条经验 获得超8个赞

@lin_yue: 

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

查看完整回答
反对 回复 2019-01-21
?
慕无忌1623718

TA贡献1744条经验 获得超4个赞

data里面是字符串,并且是"True"不是“true”,是“False”不是"false"

查看完整回答
反对 回复 2019-01-21
  • 11 回答
  • 0 关注
  • 425 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信