how to format table.ajax.params() to same format as a normal ajax request?

how to format table.ajax.params() to same format as a normal ajax request?

gwiqugwiqu Posts: 8Questions: 4Answers: 1

var params = table.ajax.params();
window.location.href = './ServerSide.php?ExportToExcel=Yes&dt='+JSON.stringify( params );

im following this code, but the code that gets sent to my server does not follow the format of a normal AJAX request, is there anyway i can convert "params" to the same format?

im using window.location.href as i am creating a button to download the filtered data table

Answers

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    I’m not sure what you mean - in that URL, you have a dt parameter which contains JSON. In PHP for example you could use:

    json_decode( $_GET[‘dt’] );
    

    Not that you should use encodeURIComponent() to make the dt value URL safe there.

    Or do you mean you don’t want to send params as JSON? If so, you could use jQuery’s param method.

    Allan

  • gwiqugwiqu Posts: 8Questions: 4Answers: 1

    @allan im currently using python as my backend with flask and if i want to get the search value in a normal ajax request for the data table generation, i could use

    search = request.args.get('search[value]')

    but for
    window.location.href = './ServerSide.php?ExportToExcel=Yes&dt='+JSON.stringify( params );

    i need to use

    json.loads(request.args.get('dt'))['search']['value']

    instead, i was wondering if i could change the format to match so that i can combine my code into a single function instead of having what is essentially the same code in 2 places

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    edited August 2022

    I'm with you now thanks. Your want the jQuery params method I mentioned in that case.

    Allan

Sign In or Register to comment.