dsxay48646 2014-06-17 19: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 16: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条)

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统