Jump to content

Jquery data table post data from variable


gongpex

Recommended Posts

Hello everyone

 

I had tried to post data using jquery data table but it didn't work, here is my code:

function table(){
     $('#page').DataTable( {
	    "pageLength": 5,
	    "bAutoWidth": true,
        "processing": true,
        "serverSide": true,
		"destroy": true,
		"columnDefs": [
		   {"bSortable": false, "aTargets": [ 1, 2, 3, 4]},
		   { targets: 0 },
		   { targets: 1 },
		   { className:'text-center',targets: 2 },
		   { className:'text-center', targets: 3 },
		   { className:'text-center', render:function(data,type,row){
					return '<a style="cursor:pointer" class="btn btn-xs btn-info my_popup_open" rowid="'+row[6]+'">Edit Data</a>';
		   },targets: 4 },

		],
		"ajax" : {
			"url" :  "<?php echo base_url('index.php/loc/data');?>",
			"type" : "POST",
			"data": $("#location").val()
                }
		
    });
 }

and this my php code :

 function data(){
            $location = $this->input->post("id_location");
		
	    $start = $_GET["start"];
		$rowPerPage = $_GET["length"];
		$orderbyIndex = $_GET["order"][0]["column"];
		$orderby = $_GET["order"][0]["dir"];
		$search = $_GET["search"]["value"];
		$draw = $_GET["draw"];

           $query = $this->db->query("select * from location where id_loc = '$location'");
          
           // another code on bottom
}

I want data from Jquery data tables ($("#location").val()) can be sent to my php code

 

Q : what I must do?

 

please help me

 

Thanks

Edited by gong
Link to comment
Share on other sites

are you checking for console errors? checking that data is what you expect it to be? checking the POST request that the browser is sending to verify what's actually getting sent across the wire? Does DataTables have an API you can use to get the data instead (that would seem more practical to me). In general, it's not clear from your post what "doesn't work" means since there's not much detail here to know what debugging you've done.

Link to comment
Share on other sites

hmm ok, thanks for answer before,

 

my expectation actually :

 

to make select option that I've made, work when it changed.

 

Here is my screen shot :

 

672l5.png

If I used code on above the result is : "undefined property : start" and etc

 

please help me

 

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...