2016-12-29 64 views
0
var User = Backbone.Model.extend({ 
      defaults: { 
       user_name: "", 
       user_email: "", 
       user_password: "", 
      }, 

      initialize: function() { 
       console.log('user has been intialized'); 
      }, 
      urlRoot: 'http://localhost/reddit/index.php/user_account/user' 
     }); 

     $(document).ready(function(){ 
      $("#submit").click(function(){ 
       var email = $("#uname").val(); 
       var password = $("#upass").val(); 

      if(email==''||password=='') 
       { 
        alert("Please Fill All Fields"); 
       } 
       else 
       { 
// AJAX Code To Submit Form. 
        var user = new User({user_email: email, user_password:password}); 
        user.fetch({ 
         success: function() { 
          var view1 = new SampleView({model: user, el: $("#logged_user")}); 
          view1.render(); 
         } 
        }); 
       } 
       return false; 
      }); 
     }); 

這是我的代碼。我需要在codeigniter中將user_name和user_password發送給控制器。我檢查了從控制器中的視圖發送的值。那些是空的。誰能幫我 ?由於發送表單數據到控制器使用骨幹js

+1

'.fetch'將GET請求不發送任何數據。嘗試使用'user.save()',它會發出一個POST請求或者只是調用一個自定義的jQuery'.ajax'調用。 –

回答

0

您還沒有分享您的控制器代碼想到這兒過得您的控制器必須喜歡這個...嘗試一次

public function user($email,$password) 
{ 

    echo $email."<br/>"; 
    echo $password; 

    //perform operations 

} 

或者你可以讓jQuery的ajax()電話這樣的...

$.ajax({ 
    type:'POST', 
    url:'http://localhost/reddit/index.php/user_account/user', 
    data:{user_email: email, user_password:password}, 
    success:function() 
    { 
     var view1 = new SampleView({model: user, el: $("#logged_user")}); 
     view1.render();   
    } 
}); 

並在控制器

public function user() 
{ 

    $email = $this->input->post('user_email'); 
    $password = $this->input->post('user_password'); 

    //perform operations 

} 
+0

謝謝.. :-) – Pubudu