pass value of select to ajax data

pass value of select to ajax data

spanzspanz Posts: 1Questions: 1Answers: 0

Hello,

I don't know how to pass value to ajax data, can you help me please?

$(document).ready(function(){
            var petsEditor=new $.fn.dataTable.Editor({
                ajax:'controllers/pets.php',
                table:'#pets',
                fields:[
                    {label:'Breed:',name:'pets.idbreed',type:'select2',opts:{placeholder:'',allowClear:true}},
                    {label:'Sire:',name:'pets.idsire',type:'select2',opts:{placeholder:'',allowClear:true,
                        ajax:{
                            url:'controllers/sires.php',
                            dataType:'json',
                            data:function(params){
                                var qp={
                                    idbreed: PETS.IDBREED    <====== this is my problem
                                    params:params._type,
                                };
                                return qp;
                            }
                        },
                        processResults:function(data){
                            return{
                                results:data
                            };
                        }
                    }},

thank you very much

Answers

  • kthorngrenkthorngren Posts: 17,265Questions: 25Answers: 4,098

    Take a look at the examples in the ajax.data docs. You need to add properties to the parameter (which is the data being sent) you are passing into the function. There is no return statement.

            data: function ( d ) {
                d.user_id = $('#user_id').val();
            }
    

    Kevin

Sign In or Register to comment.