How to set two different ajax post format?

How to set two different ajax post format?

march361march361 Posts: 3Questions: 2Answers: 0
edited May 2022 in Free community support
document.onreadystatechange = function () {
        if (document.readyState === 'complete') {
            $(function () {
                $("#example1").DataTable({
                    "serverSide": true,
                    "ajax": {
                        "url": "myapi",
                        "type": "POST",
                        'data': function (d) {
                                     my custom post format 1 
                        }
                    },

I have the above code to set the ajax post format and it will be called when a button is clicked.
Now I want to add another button to reload the table with another different ajax parameter.
Is there any ways to do so ?
Thank you so much

Edited by Kevin: Syntax highlighting. Details on how to highlight code using markdown can be found in this guide

Answers

  • march361march361 Posts: 3Questions: 2Answers: 0

    Sorry for the ugly code format. I dont know how to paste it properly.
    You may have a look in jsfiddle
    https://jsfiddle.net/2mwjL3gn/

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    You need to have the triple back ticks on their own lines. I updated your post to fix that.

    One option is within the ajax.data function you can use if statements to determine what parameters to send. The button can set a flag to send a certain set then in the function reset the flag.

    Kevin

Sign In or Register to comment.