admin管理员组文章数量:1026989
I have created an edit form in which values are to be send in my codeigniter controller via ajax. The values in the form that are to be updated is passed using serialized function var curr_val = $("#edit_currency").serialize();
but the id of the values to be updated is not included in the serialize method and is just passed to my javascript function via var curr_id = $("#curr_id").val();
The problem is I cannot successfully passed this 2 variable in ajax to be received in my controller function. There is no updating happens. How can I get this done? Thanks a lot. Here are my codes
View:
<?php
//echo form_open('/display/student_update');
foreach($curr_values as $row){
echo"<input type='hidden' name='curr_id' id='curr_id' value=".$row->id.">";
?>
<form method="post" action="" id="edit_currency">
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_name;?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo"<input type='text' name='currency[pretty_name]' id='pretty_name' value=".$row->pretty_name.">"; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_code; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo form_input($currency_code,$row->currency_code);?></strong> </div>
</div>
?>
<script type="text/javascript">
$(function(){
$("#currency_save").click(function(){
var curr_id = $("#curr_id").val();
var curr_val = $("#edit_currency").serialize();
alert(curr_id);
alert(curr_val);
$.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
dataType:'json',
data: {'curr_values':curr_val,'curr_id':curr_id},
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
</script>
Controller:
function update_currencies(){
$curr_val=$this->input->post('curr_values');
$curr_id = $this->input->post('curr_id');
$query = $this->course_booking_model->update_currencies($curr_id,$curr_val);
if($query){
$notification = "Success";
}
else{
$notification = "Failed";
}
echo json_encode(array('notify'=>$notification));
}
I have created an edit form in which values are to be send in my codeigniter controller via ajax. The values in the form that are to be updated is passed using serialized function var curr_val = $("#edit_currency").serialize();
but the id of the values to be updated is not included in the serialize method and is just passed to my javascript function via var curr_id = $("#curr_id").val();
The problem is I cannot successfully passed this 2 variable in ajax to be received in my controller function. There is no updating happens. How can I get this done? Thanks a lot. Here are my codes
View:
<?php
//echo form_open('/display/student_update');
foreach($curr_values as $row){
echo"<input type='hidden' name='curr_id' id='curr_id' value=".$row->id.">";
?>
<form method="post" action="" id="edit_currency">
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_name;?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo"<input type='text' name='currency[pretty_name]' id='pretty_name' value=".$row->pretty_name.">"; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_code; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo form_input($currency_code,$row->currency_code);?></strong> </div>
</div>
?>
<script type="text/javascript">
$(function(){
$("#currency_save").click(function(){
var curr_id = $("#curr_id").val();
var curr_val = $("#edit_currency").serialize();
alert(curr_id);
alert(curr_val);
$.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
dataType:'json',
data: {'curr_values':curr_val,'curr_id':curr_id},
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
</script>
Controller:
function update_currencies(){
$curr_val=$this->input->post('curr_values');
$curr_id = $this->input->post('curr_id');
$query = $this->course_booking_model->update_currencies($curr_id,$curr_val);
if($query){
$notification = "Success";
}
else{
$notification = "Failed";
}
echo json_encode(array('notify'=>$notification));
}
Share
Improve this question
asked Aug 18, 2013 at 23:17
EliEli
1,2765 gold badges32 silver badges63 bronze badges
1
- What is the response you get from server, when you see it in the Developer tools? Cannot pass means your CI function is not executed at all or executed but you miss the values? – Nish Commented Aug 19, 2013 at 6:11
1 Answer
Reset to default 2 $.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
data: curr_values + '&curr_id=' + curr_id,
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
You converted the curr values to query string so you just need to concat the curr id as query string as well.
I have created an edit form in which values are to be send in my codeigniter controller via ajax. The values in the form that are to be updated is passed using serialized function var curr_val = $("#edit_currency").serialize();
but the id of the values to be updated is not included in the serialize method and is just passed to my javascript function via var curr_id = $("#curr_id").val();
The problem is I cannot successfully passed this 2 variable in ajax to be received in my controller function. There is no updating happens. How can I get this done? Thanks a lot. Here are my codes
View:
<?php
//echo form_open('/display/student_update');
foreach($curr_values as $row){
echo"<input type='hidden' name='curr_id' id='curr_id' value=".$row->id.">";
?>
<form method="post" action="" id="edit_currency">
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_name;?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo"<input type='text' name='currency[pretty_name]' id='pretty_name' value=".$row->pretty_name.">"; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_code; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo form_input($currency_code,$row->currency_code);?></strong> </div>
</div>
?>
<script type="text/javascript">
$(function(){
$("#currency_save").click(function(){
var curr_id = $("#curr_id").val();
var curr_val = $("#edit_currency").serialize();
alert(curr_id);
alert(curr_val);
$.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
dataType:'json',
data: {'curr_values':curr_val,'curr_id':curr_id},
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
</script>
Controller:
function update_currencies(){
$curr_val=$this->input->post('curr_values');
$curr_id = $this->input->post('curr_id');
$query = $this->course_booking_model->update_currencies($curr_id,$curr_val);
if($query){
$notification = "Success";
}
else{
$notification = "Failed";
}
echo json_encode(array('notify'=>$notification));
}
I have created an edit form in which values are to be send in my codeigniter controller via ajax. The values in the form that are to be updated is passed using serialized function var curr_val = $("#edit_currency").serialize();
but the id of the values to be updated is not included in the serialize method and is just passed to my javascript function via var curr_id = $("#curr_id").val();
The problem is I cannot successfully passed this 2 variable in ajax to be received in my controller function. There is no updating happens. How can I get this done? Thanks a lot. Here are my codes
View:
<?php
//echo form_open('/display/student_update');
foreach($curr_values as $row){
echo"<input type='hidden' name='curr_id' id='curr_id' value=".$row->id.">";
?>
<form method="post" action="" id="edit_currency">
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_name;?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo"<input type='text' name='currency[pretty_name]' id='pretty_name' value=".$row->pretty_name.">"; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo $lbl_currency_code; ?></strong> </div>
</div>
<div class="row">
<div class="span4"><strong><?php echo form_input($currency_code,$row->currency_code);?></strong> </div>
</div>
?>
<script type="text/javascript">
$(function(){
$("#currency_save").click(function(){
var curr_id = $("#curr_id").val();
var curr_val = $("#edit_currency").serialize();
alert(curr_id);
alert(curr_val);
$.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
dataType:'json',
data: {'curr_values':curr_val,'curr_id':curr_id},
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
$("html, body").animate({ scrollTop: 0 }, 600);
return false;
});
});
</script>
Controller:
function update_currencies(){
$curr_val=$this->input->post('curr_values');
$curr_id = $this->input->post('curr_id');
$query = $this->course_booking_model->update_currencies($curr_id,$curr_val);
if($query){
$notification = "Success";
}
else{
$notification = "Failed";
}
echo json_encode(array('notify'=>$notification));
}
Share
Improve this question
asked Aug 18, 2013 at 23:17
EliEli
1,2765 gold badges32 silver badges63 bronze badges
1
- What is the response you get from server, when you see it in the Developer tools? Cannot pass means your CI function is not executed at all or executed but you miss the values? – Nish Commented Aug 19, 2013 at 6:11
1 Answer
Reset to default 2 $.ajax({
type: "POST",
url: "<?php echo base_url();?>currencies/update_currencies",
data: curr_values + '&curr_id=' + curr_id,
success: function(data)
{
if(data.notify=="Success"){
console.log(data.notify);
}
else{
console.log(data.notify);
}
}
});
You converted the curr values to query string so you just need to concat the curr id as query string as well.
本文标签:
版权声明:本文标题:javascript - How to pass multiple variables through ajax to codeigniter controller? One variable is via serialize - Stack Overfl 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745654692a2161527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论