Send id via POST in Jquery

Asked

Viewed 222 times

0

I’m working on an implementation of Datatables, but the need arose to send id to make filters:

		$(document).ready(function() {
			var dataTable = $('#employee-grid').DataTable( {
                responsive: false,
				"order": [[ 1, "asc" ]],
				"aoColumns": [
					null,
					null,
					null,					
					null
				],				
				//"scrollY": 400,
				"scrollX": true,
				"iDisplayLength": 100,
				"processing": true,
				"serverSide": true,
				"ajax":{
					url :"../php/admin_gerente_cidade.php",
					type: "post",
					error: function(){
						$(".employee-grid-error").html("");
						$("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">Nenhum resultado encontrado</th></tr></tbody>');
						$("#employee-grid_processing").css("display","none");
					}
				}
			} );
		} );

If I put

url :"../php/admin_gerente_cidade.php?id=<?php $id; ?>"

Doesn’t work.

It would be possible to pass an id via POST?

  • you need to pass the date: {id: id}

  • 1

    I’m not very familiar with php, but where the $id is, how is it not string interpolation (because of the <?php ? >, give an echo before the $id and see if it resolves.

1 answer

2


Just inform the property data, follows below as would be in your case, replace seu_id for the amount you need.

$(document).ready(function() {
            var dataTable = $('#employee-grid').DataTable( {
                responsive: false,
                "order": [[ 1, "asc" ]],
                "aoColumns": [
                    null,
                    null,
                    null,                   
                    null
                ],              
                //"scrollY": 400,
                "scrollX": true,
                "iDisplayLength": 100,
                "processing": true,
                "serverSide": true,
                "ajax":{
                    url :"../php/admin_gerente_cidade.php",
                    type: "post",
                    data: {id: seu_id},
                    error: function(){
                        $(".employee-grid-error").html("");
                        $("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">Nenhum resultado encontrado</th></tr></tbody>');
                        $("#employee-grid_processing").css("display","none");
                    }
                }
            } );
        } );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.