简体   繁体   中英

Is it possible to pass a true/false value to a ajax function?

I want to make a sorting function in ajax but the sorting function can be enable or disable by the user
I tried to pass a variable when user clicks a button, however the ajax still using the old variable
Is it possible to do it?

Here is my code

 var sort_or_not = "true";  
 function click_button_to_not_sort_test()
{sort_or_not = "false";}
//function to make my ajax not sort?
function approve_edit()
{

      $('#approve_table').dataTable({
        "processing": true,
        "paging":false, 
        "bPaginate":false,
        "bFilter": false,
        "scrollY":        300,
        "info": false, 
        //"bSort" : false,
        "aoColumnDefs": [
            { 'bSortable': sort_or_not,   //This is the variable that i want    to to passed from the button click 
              'aTargets': [ 0, 1, 2,3 ] 
            },
            { 'width': "15%", 
              'aTargets': [ 0, 2, 3]
            }
            ],
        "ajax": "approve_table.php?approve=1"
      });

Don't put true or false in quotes. So first lines should be:

var sort_or_not = true;
function click_button_to_not_sort_test() {
    sort_or_not = false;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM