dsxay48646 2014-06-17 11:00
浏览 32
已采纳

骨干和检查记录的响应

I use a bacbone in a first time. And i try to login There is a php.code

$data = json_decode(file_get_contents('php://input'));
if ($data) {
    $name = $data->{'uname'};
    $passwd = $data->{'passwd'};
    echo ($name == "myname" && $passwd == "mypass") ? "Login success" : "Wrong name or password";
}

And a backbone code

var modelLogin = Backbone.Model.extend({
    url: 'login.php'
});
modelLogin.save({
    uname: "myName",
    passwd: "myPassww",
});

How to see (e.g with alert or console.log) thw words "Login success" or "Wrong name or password"?

Thank you!

  • 写回答

2条回答 默认 最新

  • duanlongling5308 2014-06-18 08:24
    关注

    Backbone can help you with that.

    Every request to server using backbone.model, uses from behind jquery(ajax). So use Backbone or Jquery in this case have no difference

    //Inside your model
    LoginUser:->
        @fetch(
             success:=>
                 trigger 'authenticated'
             error:=>
                 trigger 'invalidUser'
        )
    

    Try to not use save to user authentication, use save only when you post(save data) on server.

    The best approach in this case could be fetch the content to server and return the userID or something about the user if the user login and password are both correct.

    If you'd like to know the status code returned from server, you can get it from fetch. Like this:

    //Model
      LoginUser:->
        result = @fetch(
                    success:=>
                        trigger 'authenticated'
                    error:=>
                        trigger 'invalidUser'
        )
    

    more info here http://backbonejs.org/#Model-fetch

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部