是否可以将true/false值传递给ajax函数

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

本文关键字:值传 ajax 函数 false true 是否      更新时间:2023-09-26

我想在ajax中创建一个排序函数但是用户可以启用或禁用排序功能
我试图在用户单击按钮时传递一个变量,但是ajax仍在使用旧变量
有可能做到吗?

这是我的代码

 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"
      });

不要将truefalse放在引号中。所以第一行应该是:

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