2014-01-22 47 views
0

我想打電話休息服務(後)當我按下按鈕登錄,但它不啓動任何服務,它只是添加一個「?」在我的應用程序的URL的末尾。呼叫服務休息點擊與骨幹

這裏是我的JS:

(function ($) { 
var authentication = Backbone.Model.extend({ 
    defaults: { 
      Username: "", 
      Password: "" 
     }, 
     url:'../../rest/login' 
}); 



var LoginView = Backbone.View.extend({ 
    model: new authentication(), 
    el: $("#login-form"), 
    events: { 
     "click button#login": "login" 
    }, 

    login: function(){ 
     alert("ici"); 
     this.model.save({username: this.$el.find("#inUser")}, { 
     password: this.$el.find("#inPswd")}, { 
      success: function() { 
       /* update the view now */ 
      }, 
      error: function() { 
       /* handle the error code here */ 
      } 
     }); 
    } 

}) 
}) 
(jQuery); 

這裏是我的表格:

<form class="form-inline"> 
<div class="form-group"> 
<input type="text" class="form-control" placeholder="Username" id="inUser"></input> 
<input type="password" class="form-control" placeholder="Password" id="inPswd"></input> 
<button id="login">Login</button> 
</div> 
</form> 

回答

0

你必須與你.save()方法調用一個問題,因爲你在兩個不同的對象發送usernamepassword

還要停止添加問號?標誌(停止提交表單),您需要將event.preventDefault();和/或return false;添加到您的按鈕點擊處理程序。

這裏是一個修復:

login: function(event) { 
    event.preventDefault(); 
    alert("ici"); 
    this.model.save({ 
      username: this.$el.find("#inUser"), 
      password: this.$el.find("#inPswd") 
     }, { 
      success: function() { 
       /* update the view now */ 
      }, 
      error: function() { 
       /* handle the error code here */ 
      } 
    }); 
    return false; 
}