add custom parameters to ajax url after initialization and get new json

add custom parameters to ajax url after initialization and get new json

jnajna Posts: 19Questions: 5Answers: 0

Hi
What is the best way to add parameters to the ajax url and get the new filtered json from the server?
What I want is to change the json data when doing an 'onchange' on a select with that selected value
So: I get the value:

type=mySelect[MySelect.selectedIndex].value 
and append it to the ajaxurl:  this.apiUrl += '&type=' + type

that is no problem
When I initialize datatables first my ajaxurl looks like this:
http://127.0.0.1:3000/mockData/searchResult.json?a=1&draw=1&columns%5B0%5D%5Bdata%5D=function&columns%5B0%5D%5Bname%5D=&columns%5B0%5D%5Bsearchable%5D=true&columns%5B0%5D%5Borderable%5D=false&columns%5B0%5D%5Bsearch%5D%5Bvalue%5D=&columns%5B0%5D%5Bsearch%5D%5Bregex%5D=false&start=0&length=10&search%5Bvalue%5D=&search%5Bregex%5D=false&_=1536235815080

And when i try to modify/add parameter it looks like this: http://127.0.0.1:3000/mockData/searchResult.json?a=1&type=type-2

So all the original parameters are stripped since they are attached by datatable init.

Am I going down the wrong path or is there a better way to do this?

My initialization looks like this:

table.DataTable( {
            "processing": true,
            "serverSide": true,
            "searching": false,
            "ordering": false,
            "deferRender": true,
            "lengthChange": false,
            "info": false,
            "paging": true,
            'retrieve': true,
            "ajax": {
                url: this.apiUrl
            },
} );

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.