ajax.data with updating value

ajax.data with updating value

matt_benettmatt_benett Posts: 6Questions: 1Answers: 0

I have a selectbox, that I want to use in my serverside processing of each ajax request sent through.

I have the below:

          $('#example').dataTable( {
               "ajax": {
                 "url": "data.json",
                 "data": {
                     "myfilter": $('#otherfilter').children("option:selected").val()
                 }
               }
             } );

My issue is when the page loads the value is 1. And even if I change it after, the ajax request keeps sending 1, it never re-updates to on each request.

Any ideas please.

Replies

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

    Hi @matt_benett ,

    It's probably because it sets the value to that value when first called, and then it's not being updated. Try chaging it to be a function that returns the value, that way it will always get the current value.

    Cheers,

    Colin

  • matt_benettmatt_benett Posts: 6Questions: 1Answers: 0

    champion, thank you

                $('#example').dataTable( {
                  "ajax": {
                    "url": "data.json",
                    "data": function ( d ) {
                      return $.extend( {}, d, {
                        "extra_search": $('#extra').val()
                      } );
                    }
                  }
                } );
    
This discussion has been closed.