do not want to send all query string parameter

do not want to send all query string parameter

dinkerdinker Posts: 6Questions: 1Answers: 0

Hi,

Currently when ajax is fired, it will send all query parameter to the server, instead I want to send only those parameters which are used by the user. for example if user search for filter, I want to send only that parameter.

Is there anyway , where we can achieve this ??

any help would be great

Regards,
Dinker

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,431Questions: 1Answers: 10,457 Site admin

    You can use ajax.data to manipulate the data object sent to the server, including removing items.

    Allan

  • dinkerdinker Posts: 6Questions: 1Answers: 0
    edited February 2016

    Hi allan,

    Javascript code below:

     var table = $('#filterSort').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "window.location.href",
                "data": function ( d ) {
                    return $.extend( {}, d, {
                             "extra_search": 796
                    });
             }
              }
        });
    
    
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    
    Output:
    draw:7
    columns[0][data]:0
    columns[0][name]:
    columns[0][searchable]:true
    columns[0][orderable]:true
    columns[0][search][value]:rtr6
    columns[0][search][regex]:false
    columns[1][data]:1
    columns[1][name]:
    columns[1][searchable]:true
    columns[1][orderable]:true
    columns[1][search][value]:
    columns[1][search][regex]:false
    columns[2][data]:2
    columns[2][name]:
    columns[2][searchable]:true
    columns[2][orderable]:true
    columns[2][search][value]:
    columns[2][search][regex]:false
    order[0][column]:0
    order[0][dir]:asc
    start:0
    length:10
    search[value]:sdg
    search[regex]:false
    extra_search:796
    _:1455111107989
    
    
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    
    my expectation:
    extra_search:796
    
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    

    So as you can see all these columns parameter is coming, I dont want to send all these parameter.
    can you please help me to disable all these parameters ??

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

  • allanallan Posts: 63,431Questions: 1Answers: 10,457 Site admin
    Answer ✓

    Two options:

    1. Use delete to remove the items you don't want.
    2. Instead of extending d, just extend an empty object and then select the items you want to use from d in the extending object.

    Allan

  • dinkerdinker Posts: 6Questions: 1Answers: 0

    yeah that will be excellent Allan :)

    can you please show me the code snippets, since I am new here.

    Many thanks

  • dinkerdinker Posts: 6Questions: 1Answers: 0
    edited February 2016

    Hi Allan,

    I have found it, thanks for your help :)

    $(document).ready( function () {
     var table = $('#filterSort').DataTable({
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "window.location.href",
                "data": function( result ) {
                    // Do stuff
                    var newresult = {"test":"225"}
                    return newresult;
                  }
              }
        });
    } );
    
  • dinkerdinker Posts: 6Questions: 1Answers: 0
    edited February 2016

    Hi,

    I have one more question since here "data" can also be used as function can I do this stuff ?? this is basically to send my parameters to ajax using datatables.

    $(document).ready( function () {
    "ajax": {
                "url": "window.location.href",
                "data": function( result ) {
                    // Do stuff
                    var submitData = {};
                    $(".getkey").each(function(key,value){
                        var val = value.value;
                        var named  = value.name;
                            submitData[named] = val;
                        });
                    return submitData;
                  }
              }
    });
    
  • allanallan Posts: 63,431Questions: 1Answers: 10,457 Site admin

    You can do anything you want since its just a regular function.

    Allan

  • dinkerdinker Posts: 6Questions: 1Answers: 0

    Hi Allan,

    I am appending 2 parameters but why this is coming in my url "&_=1455195488296" & how can I avoid this.

    url : https://xxxx/catalog?blLocale=enUS&name=sdfgwe&_=1455195488296

  • allanallan Posts: 63,431Questions: 1Answers: 10,457 Site admin

    That is the jQuery anti cache parameter. Set cache: true if you want to avoid that.

    Allan

This discussion has been closed.