How to pass a variable in the ajax url

How to pass a variable in the ajax url

LaRichyLaRichy 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

Answers

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770

    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

  • LaRichyLaRichy Posts: 17Questions: 4Answers: 0

    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!

  • LaRichyLaRichy Posts: 17Questions: 4Answers: 0

    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...

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    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

  • kthorngrenkthorngren Posts: 20,309Questions: 26Answers: 4,770
    Answer ✓

    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

  • LaRichyLaRichy Posts: 17Questions: 4Answers: 0

    This thread helped me :) Tnx!
    Now to find a way to reset the URL back to default...

  • colincolin Posts: 15,144Questions: 1Answers: 2,586

    Hi @LaRichy ,

    You can use ajax.url() to modify the URL,

    Cheers,

    Colin

This discussion has been closed.