How to call a controller function by using ajax
up vote
3
down vote
favorite
I have two radio button and one check box..The radio buttons are all and selected when all is checked i have to load one view page and if a checkbox is checked i want to perform different action and i have to load different view page..I tried it with if and else statment but it does not give me a expected result..so i tried it with different function name..If a check box is checked i have to make a call on Receipt Reg chek()..I tried it with ajax but i did not get a call to Receipt Reg check() it still calls a Receipt Reg Check1() that is loaded on a form action..what changes have to be done on my code..Help me to solve this issue
Controller Code:
public function Receipt_reg_check1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$item=$this->input->post('item');
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}}
public function Receipt_reg_check()
{
if($this->input->post('all'))
{
if($this->input->post('item')){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
}}
Html Page:
<form class="form-horizontal" action="<?=site_url('welcome/Receipt_reg_check1')?>" method="POST" target="_blank">
<input type="radio" class='rd'name="all" value="op1" checked=""> All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" id="AcNo" >Item description
Ajax Code:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>welcome/Receipt_reg_check",
data:{id:$(this).val()},
datatype:'json',
success: function (data) {
var res = jQuery.parseJSON(data);
$("#AcNo").val(res);
}
});
});
</script>
ajax codeigniter
add a comment |
up vote
3
down vote
favorite
I have two radio button and one check box..The radio buttons are all and selected when all is checked i have to load one view page and if a checkbox is checked i want to perform different action and i have to load different view page..I tried it with if and else statment but it does not give me a expected result..so i tried it with different function name..If a check box is checked i have to make a call on Receipt Reg chek()..I tried it with ajax but i did not get a call to Receipt Reg check() it still calls a Receipt Reg Check1() that is loaded on a form action..what changes have to be done on my code..Help me to solve this issue
Controller Code:
public function Receipt_reg_check1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$item=$this->input->post('item');
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}}
public function Receipt_reg_check()
{
if($this->input->post('all'))
{
if($this->input->post('item')){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
}}
Html Page:
<form class="form-horizontal" action="<?=site_url('welcome/Receipt_reg_check1')?>" method="POST" target="_blank">
<input type="radio" class='rd'name="all" value="op1" checked=""> All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" id="AcNo" >Item description
Ajax Code:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>welcome/Receipt_reg_check",
data:{id:$(this).val()},
datatype:'json',
success: function (data) {
var res = jQuery.parseJSON(data);
$("#AcNo").val(res);
}
});
});
</script>
ajax codeigniter
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I have two radio button and one check box..The radio buttons are all and selected when all is checked i have to load one view page and if a checkbox is checked i want to perform different action and i have to load different view page..I tried it with if and else statment but it does not give me a expected result..so i tried it with different function name..If a check box is checked i have to make a call on Receipt Reg chek()..I tried it with ajax but i did not get a call to Receipt Reg check() it still calls a Receipt Reg Check1() that is loaded on a form action..what changes have to be done on my code..Help me to solve this issue
Controller Code:
public function Receipt_reg_check1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$item=$this->input->post('item');
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}}
public function Receipt_reg_check()
{
if($this->input->post('all'))
{
if($this->input->post('item')){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
}}
Html Page:
<form class="form-horizontal" action="<?=site_url('welcome/Receipt_reg_check1')?>" method="POST" target="_blank">
<input type="radio" class='rd'name="all" value="op1" checked=""> All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" id="AcNo" >Item description
Ajax Code:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>welcome/Receipt_reg_check",
data:{id:$(this).val()},
datatype:'json',
success: function (data) {
var res = jQuery.parseJSON(data);
$("#AcNo").val(res);
}
});
});
</script>
ajax codeigniter
I have two radio button and one check box..The radio buttons are all and selected when all is checked i have to load one view page and if a checkbox is checked i want to perform different action and i have to load different view page..I tried it with if and else statment but it does not give me a expected result..so i tried it with different function name..If a check box is checked i have to make a call on Receipt Reg chek()..I tried it with ajax but i did not get a call to Receipt Reg check() it still calls a Receipt Reg Check1() that is loaded on a form action..what changes have to be done on my code..Help me to solve this issue
Controller Code:
public function Receipt_reg_check1()
{
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$item=$this->input->post('item');
if ($this->input->post('all'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get()->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
if($this->input->post('selected'))
{
if($name = $this->input->post('businessType'))
{
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->where('PName',$name);
$this->db->select('*');
$this->db->from('purchasebill');
$this->db->order_by("date", "asc");
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->load->view('Receipt_View', $data);
}
}}
public function Receipt_reg_check()
{
if($this->input->post('all'))
{
if($this->input->post('item')){
$startdate = $this->input->post('SDate');
$enddate = $this->input->post('EDate');
$date = str_replace('/', '-', $startdate);
$newDate = date("Y-m-d", strtotime($date));
$date2 = str_replace('/', '-', $enddate);
$newDate2 = date("Y-m-d", strtotime($date2));
$data['startdate'] = $startdate;
$data['enddate'] = $enddate;
$this->db->where('billdate >=', $newDate);
$this->db->where('billdate <=', $newDate2);
$this->db->select('vno,Prdtname,Qty,bundle');
$this->db->from('purchaseitem');
$this->db->order_by("vno", "asc");
$this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
$query = $this->db->get('')->result_array();
$data['query'] = $query;
$this->db->where('date >=', $newDate);
$this->db->where('date <=', $newDate2);
$this->db->select();
$this->db->from('purchasebill');
$this->db->order_by('voucherno');
$this->db->group_by('voucherno');
$this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
$query = $this->db->get('')->result_array();
$data['query1'] = $query;
$this->load->view('Receipt_View1',$data);
}}
}}
Html Page:
<form class="form-horizontal" action="<?=site_url('welcome/Receipt_reg_check1')?>" method="POST" target="_blank">
<input type="radio" class='rd'name="all" value="op1" checked=""> All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" id="AcNo" >Item description
Ajax Code:
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "<?php echo base_url();?>welcome/Receipt_reg_check",
data:{id:$(this).val()},
datatype:'json',
success: function (data) {
var res = jQuery.parseJSON(data);
$("#AcNo").val(res);
}
});
});
</script>
ajax codeigniter
ajax codeigniter
asked Nov 19 at 6:18
dhara
23710
23710
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50
add a comment |
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
put
$this->load->view('Receipt_View',$data);
instead of
$this->load->view('Receipt_View1',$data);
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
put
$this->load->view('Receipt_View',$data);
instead of
$this->load->view('Receipt_View1',$data);
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
add a comment |
up vote
0
down vote
put
$this->load->view('Receipt_View',$data);
instead of
$this->load->view('Receipt_View1',$data);
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
add a comment |
up vote
0
down vote
up vote
0
down vote
put
$this->load->view('Receipt_View',$data);
instead of
$this->load->view('Receipt_View1',$data);
put
$this->load->view('Receipt_View',$data);
instead of
$this->load->view('Receipt_View1',$data);
answered Nov 19 at 6:48
Mac Rathod
215
215
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
add a comment |
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
But i want to load different view page when check box is clicked..
– dhara
Nov 19 at 7:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369262%2fhow-to-call-a-controller-function-by-using-ajax%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
From what you write up here it seems like your form is not connected to the AJAX call. You should connect the ajax call to a user interaction (form button click or submit) not on document ready.
– Andrea
Nov 20 at 14:50