Welcome Guest, Not a member yet? Register   Sign In
get data in ajax
#1

[eluser][email protected][/eluser]
hi guys can someone help me. i'm trying to call the data that passes through this ajax method.
how can i get data in controller?

Thanks a lot

Code:
$( "#sortable" ).sortable({
                update: function(){
                
                            stringDiv = "";
                            $("#sortable").children().each(function(i) {
                              var li = $(this);
                             if(li.attr("class") == "ui-state-default"){
                              stringDiv += " "+li.attr("id") + '=' + i + '&';
                              }
                            });
                            
                             $.ajax({
                               type: "POST",
                               url: "<?=base_url().'admin/updatelist/'?>",
                               data: stringDiv,
                               success: function(msg){
                                 $( "#dialog" ).dialog();
                                 console.log(stringDiv);
                                    // [removed].reload( true );
                               }
                             });

                        }

            });
#2

[eluser]Pert[/eluser]
Data should be an object, so

Code:
data = [];
$("#sortable").children().each(function(i) {
   var li = $(this);
   if(li.attr("class") == "ui-state-default"){
      data[li.attr("id")] = i;
   }
});

$.ajax({
   type: "POST",
   url: "<?=base_url().'admin/updatelist/'?>",
   data: data,
   ...
});
#3

[eluser][email protected][/eluser]
Hi @pert thank you for you response. then how can i get it using controller?

Thank you.
#4

[eluser]Pert[/eluser]
Code:
class admin extends CI_controller
{
   function updatelist()
   {
      echo '<pre>'.print_R($_POST, true).'</pre>';
   }
}

Looking at your code and what it does, you might want to add everything into single POST variable with data<b>['sortorder']</b>[li.attr("id")] = i;

Then you can easily loop through $this->input->post(<strong>'sortorder'</strong>);
#5

[eluser][email protected][/eluser]
Thanks a lot will try it later and get back to if will work. thank you Pert




Theme © iAndrew 2016 - Forum software by © MyBB