2014-01-31 16 views
0

我嘗試當點擊表單提交按鈕它定位到新頁面相同的窗口動態但它不會加載細節,但它導航到該頁面。我發送我的代碼也請幫助我。當點擊提交按鈕它導航到新頁面相同的窗口**動態加載**使用`meteor`

Html頁面

<head> 
    <title>sample</title> 
    <link rel="stylesheet" type="text/css" href="style.css" /> 
</head> 
<body> 
<div class="container"> 
    {{> header}}  
    {{> body}}   
    {{> footer}} 
</div> 
<div class="row-fluid"> 
    {{render-Router}} 
</div> 
</body> 
<template name="header"> 
    <header> 
     <div class="header"> 
     <a href="http://localhost:3000/"><img src="./logo.png" style="height:100px;width:200px;"/></a> 
    </div> 
    </header> 
</template> 
<template name="body"> 
    <div class="bgbody"> 
    <div align="center"> 
    <form id="login-form" action="/admindetails"> 
     <table> 
     <p class="admin">Admin Login</p> 
     <tr> 
      <td><p for="username">Admin Name</p></td> 
      <td><input type="text" id="username" name="username" placeholder="UserName"></td> 
     </tr> 
     <tr> 
       <td><p for="password">Password</p></td> 
      <td><input type="password" id="pwd" name="password" placeholder="password"></td> 
     </tr> 
      <td></td><td><input class="btn btn-success" type="submit" value="Log In"></td> 
     <td><input class="btn btn-capsule" type="button" value="New User"></td> 
     </table> 
    </form> 
    </div> 
    </div> 
</template> 
<template name="footer"> 
    <div class="footer"> 
     <div style="padding:20px;"> 
     <div class="footerlinks"><a href="#"><p>AboutUs</p></a></div> 
     <div class="footerlinks">|</div> 
     <div class="footerlinks"><a href="#"><p>ContactUs</p></a></div> 
     <div class="copyright"><p>[email protected]_Care</p></div> 
     </div> 
    </div> 
</template> 

客戶端代碼:

if (Meteor.isClient) { 
    Meteor.Router.add({ 

    '/admindetails':'admindetails' 

    }) 
    Template.body.events 
    ({ 
    'submit #login-form' : function (e,t) 
{ 
     /* template data, if any, is available in 'this'*/ 
     if (typeof console !== 'undefined') 

     console.log("You pressed the button"); 
     e.preventDefault(); 
    /*retrieve the input field values*/ 
     var email = t.find('#username').value 
     , password = t.find('#pwd').value; 
      console.log(email); 
    Meteor.loginWithPassword(email, password, function (err) 
    { 
    if (err) 
    { 
     console.log(err); 
     alert(err.reason); 
     Session.set("loginError", true); 
    } 
    else 
    { 
     console.log(" Login Success "); 
     Meteor.Router.to("/admindetails"); 
    } 
    }); 
    } 
    }); 
} 
+0

'e.preventDefault'應該停止... –

回答

1

你管理自己提交的事件,所以沒有必要設立形式的action參數。設置該參數會導致瀏覽器在提交時加載目標頁面。只需刪除參數,事情應按預期工作。

相關問題