使用 backbone js 将表单数据发送到控制器
send form data to controller using backbone js
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;
});
});
这是我的代码。我需要将 user_name 和 user_password 发送到 codeigniter 中的控制器。我检查了从控制器中的视图发送的值。那些是空的。谁能帮我 ?谢谢
您还没有分享您的控制器代码here.I认为您的控制器一定会喜欢这个...尝试一次
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
}
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;
});
});
这是我的代码。我需要将 user_name 和 user_password 发送到 codeigniter 中的控制器。我检查了从控制器中的视图发送的值。那些是空的。谁能帮我 ?谢谢
您还没有分享您的控制器代码here.I认为您的控制器一定会喜欢这个...尝试一次
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
}