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>









share|improve this question






















  • 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















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>









share|improve this question






















  • 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













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>









share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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);





share|improve this answer





















  • But i want to load different view page when check box is clicked..
    – dhara
    Nov 19 at 7:00











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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);





share|improve this answer





















  • But i want to load different view page when check box is clicked..
    – dhara
    Nov 19 at 7:00















up vote
0
down vote













put



        $this->load->view('Receipt_View',$data);


instead of



        $this->load->view('Receipt_View1',$data);





share|improve this answer





















  • But i want to load different view page when check box is clicked..
    – dhara
    Nov 19 at 7:00













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);





share|improve this answer












put



        $this->load->view('Receipt_View',$data);


instead of



        $this->load->view('Receipt_View1',$data);






share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

Origin of the phrase “under your belt”?