Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将参数发送到公共JS文件_Javascript_Php_Jquery_Codeigniter - Fatal编程技术网

Javascript 将参数发送到公共JS文件

Javascript 将参数发送到公共JS文件,javascript,php,jquery,codeigniter,Javascript,Php,Jquery,Codeigniter,我想知道是否有可能通过使用一个公共JS文件来最小化我的代码,因为我的应用程序中会有很多数据表 所有的数据表都将有相同的主题,只有不同的是不同的数据 就像我的剧本一样 var oTable = $('#ManageForms').dataTable({ "aoColumns": [ /* ID */ { "bVisible": false, "bSortable":

我想知道是否有可能通过使用一个公共JS文件来最小化我的代码,因为我的应用程序中会有很多数据表

所有的数据表都将有相同的主题,只有不同的是不同的数据

就像我的剧本一样

    var oTable =  $('#ManageForms').dataTable({
         "aoColumns": [
             /* ID */   {
                 "bVisible":    false,
                 "bSortable":   false,
                 "bSearchable": false
             },
             /* Form Name */  null,
             /* Form Path */  null,
             /* Form CI Path */  null,
             /* Actions */  null
         ],

        "bServerSide":true,
        "bProcessing":true,
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        //"bFilter":true,
        //"sServerMethod": "POST",
        "sAjaxSource": "{{base_url()}}admin/configurations/listForms_DT/",
        "iDisplayLength": 25,
        "aLengthMenu": [[2, 25, 50, -1], [2, 25, 50, "All"]],
        /*"sEcho": 1,
        "columns":[
            {data:"FormName"},
            {data:"FormPath"},
            {data:"FormCIPath"},
            { "data": null,
                "defaultContent": "<a href='#editBtnModal' class='editBtnFunc' ><i style='color: #666666' class='fa fa-pencil fa-fw fa-2x'></i></a><a href='#' id='deleteBtn'><i style='color: #ff0000' class='fa fa-times fa-fw fa-2x'></i></a>",
                "targets": -1
            }
        ],*/
        'fnServerData'   : function(sSource, aoData, fnCallback){
            $.ajax ({
                'dataType': 'json',
                'type'    : 'POST',
                'url'     : sSource,
                'data'    : aoData,
                'success' : fnCallback
            }); //end of ajax
        },
        'fnRowCallback': function(nRow, aData, iDisplayIndex, iDisplayIndexFull) {
            $(nRow).attr("data-id",aData[0]);
            return nRow;
        }
    });

因此,不要在数据表的每一页上重复粘贴代码。我是否可以将此代码放在单个common.js文件中,并发送特定datatable的参数。

您应该将代码放在一个函数中,该函数可以在每个特定情况下调用,url作为参数:

function getData(url){
   // ...
  "sAjaxSource": url
  // ...
}
此函数可以在公共js中使用,然后在导入此文件后的任何其他代码中使用

aoColumns中的数组也可以作为param传递给另一个字段

function getData(url){
   // ...
  "sAjaxSource": url
  // ...
}