4

i am new to codeigniter, i was created some list of records from database , my problem is if i want to delete the more record using checkbox , i was get the array value as string format from jquery, but i dont know how to send this value to controller , please tell anyone

my jquery code multi select record

$('.del_mybuyer').click(function(){
        var selected = new Array();
        var inc = 0;
        $('input.selbuyer:checked').each(function(){
                selected[inc] = $(this).attr('id'); 
            inc = inc + 1;
        })      
        tdelbuy=selected.toString();                

    })

here the tdelbuy was working fine, but i dont know how to set this in session or how to send this to my controller, please tell any one

3 Answers 3

4

use $.ajax, $.post, or $.get

try this

  $.post('path/to /your/controller',{data:tdelbuy},function(html){
        alert(html);
  });    

and your controller get the posted value by

 var postedValue=$this->input->post('data'); 
 //do your stuff.
 echo "done";
Sign up to request clarification or add additional context in comments.

Comments

2

You can use any of the AJAX methods as bipen suggested. Or, if you prefer not to use AJAX, you can set the value of a hidden input to the value of your javascript variable and post it back with the rest of the form.

<form id="your_form" method="POST" action="form.php">
   <!-- your existing form inputs and layouts -->
   <input id="your_hidden_input" name="data" value="" />
</form>

And then in your javascript

$('.del_mybuyer').click(function(){
    var selected = new Array();
    var inc = 0;
    $('input.selbuyer:checked').each(function(){
            selected[inc] = $(this).attr('id'); 
        inc = inc + 1;
    })      
    tdelbuy=selected.toString();                
    $("#your_hidden_input").val(tdelbuy);
})

Comments

2

Try this:

    item = new Array();
    $("input.selbuyer:checked").each(function(index,data ) {
            item[index] = $(this).attr('id'); 
    });

    $.ajax({
        type: "POST",
        url : "your url",
        data: item,
        success:function(data){
          alert(completed);
        }       
    }); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.