Changing Ajax url from datatable

Changing Ajax url from datatable

icewizzboyicewizzboy Posts: 2Questions: 1Answers: 0
edited December 2020 in Free community support
var urlView${tableName} = "<spring:url value='/RF/list/check?radio=${bnkRefNo}'/>";

$("#${tableName}").dataTable({
                "aLengthMenu": [[3,5, 10, 15, 25, 50], [3,5, 10, 15, 25, 50]],
                "aoColumns": aoColumnsView${tableName},
                "bFilter" : true,
                "bAutoWidth" : false,
                "deferLoading" : 0,
                "iDisplayLength": 10,
                "oLanguage": {
                    "sZeroRecords": "There are no records that match your search criterion",
                    "sLengthMenu": "Rows per page&nbsp;_MENU_",
                    "sProcessing" : "Processing...",
                    "sInfoFiltered": ""
                },
                "sDom": '<"col-12">rt<"col-12"<"pagination-show"li>p><"clear">',
                "bProcessing": true, 
                "bServerSide": true,
                
                "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
                    oSettings.jqXHR = $.ajax({
                        "dataType": 'json',
                        "type": "GET",
                        "url": sSource,
                        "data": aoData,
                        "cache":    false,
                        "success": function(data){
                            if(data.errorMsg){
                                var errorMsg=data.errorMsg;
                                swal("", errorMsg, "error");
                            } else {
                                return fnCallback(data);
                            }
                        },
                        "timeout": 15000,
                        "error": handleAjaxError
                    });
                },                          
                "sAjaxSource": urlView${tableName},
                "aaSorting": [[ 0, "asc" ]],
                "bStateSave": false
            });


$('#id').on('change', function(e) {
$('#${tableName}').DataTable().ajax.url("<spring:url value="/RF/list/check"/>?radio="+$(this).val()").load();
console.log($('#allInvoiceSet').DataTable().ajax.url());
}
    @RequestMapping(value = "invoiceSet/list/check", method = RequestMethod.GET)
    public @ResponseBody String getInvoice(@RequestParam("radio") String radio, Model model,
            @RequestParam int iDisplayStart, @RequestParam int iDisplayLength,
            @RequestParam int iColumns, @RequestParam int iSortingCols, @RequestParam String sEcho,
            HttpServletResponse response,HttpServletRequest request) {
System.out.println("radio");

                        }

Hi guys, i am new to datatable here, i am trying to create a datatable that is able to change its url whenever user changes the input text. Console.log is able to print out the new value but when java is trying to get the radio, radio shows the initial value being set into the table. May i know how to can i change the url of the ajax call to be dynamic? Thank for the help

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

Answers

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

    Yep, ajax.url() is the way to go. You would need to also call ajax.reload() to get the data from that URL,

    Colin

  • icewizzboyicewizzboy Posts: 2Questions: 1Answers: 0

    I try the method. it still does not update the radio value in java side.

    I solve it by destroy the table and calls a new one with the url i need. every time the user on change.

This discussion has been closed.