How to pass a variable in the ajax url
How to pass a variable in the ajax url
LaRichy
Posts: 17Questions: 4Answers: 0
Hi,
I have a var:
var recpatid = $('input[name="id"]').val();
When I open the model of Datatables I want to use:
"ajax": "ajax_data.php?q=reciept&id="+ recpatid,
But it does not work, it does when I use:
"ajax": "ajax_data.php?q=reciept",
but I also need that ID that's in the var: recpatid.
Do you guys have any idea?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Looks like the code should work. What is not working?
What is sent in the URL of the XHR request? Use the browser's developer tools to see the URL.
Kevin
OMG... I was so stuck in my own code that I did not check that, I forgot to define the var first... Sorry and tnx!
However, I still have problems...
I choose in one datatable a user, that use has an ID and I set that ID in recpatid.
After that I let the other database table refresh with: table2.ajax.reload();
The other datatable is set to load as ajax url: "ajax": "ajax_data.php?q=reciept&id="+ recpatid,
But it doesn't work...
Hi @LaRichy ,
I would suggest passing that variable in
ajax.data
. If you use a function, like the second example on that page, then it will get the current value of that variable.Cheers,
Colin
You will probably want to use the
ajax.data
option for your parameters and set it up as a function. The below example from Colin in this thread should help.http://live.datatables.net/jimododa/1/edit
Kevin
This thread helped me Tnx!
Now to find a way to reset the URL back to default...
Hi @LaRichy ,
You can use
ajax.url()
to modify the URL,Cheers,
Colin