使用Ajax $ _GET变量作为过滤器

时间:2014-09-15 03:43:54

标签: javascript php jquery ajax datatables

我正在使用Datatables Editor来填充网格,并希望使用不同的“WHERE”子句对其进行过滤。我的代码如下:

  

的jQuery

// Valid Customer Accounts
$('#lnkValidCustomers').click(function () {
    // Redraw Grid
    customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=y&varInvalidCustomers=n').load();
});
// Invalid Customer Accounts
$('#lnkInvalidCustomers').click(function () {
    // Redraw Grid
    customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=n&varInvalidCustomers=y').load();
});
//All Customer Accounts
$('#lnkShowAllCustomers').click(function () {
    // Redraw Grid
    customersTable.ajax.url('dataGridQuery.php?varCurrentCustomers=y&varInvalidCustomers=y').load();
});
  

PHP

// Database Fields
$editor = Editor::inst( $db, 'tblCustomers', 'customerID' )
    ->fields(
        Field::inst( 'customerID' ),
        Field::inst( 'customerName' ),
        Field::inst( 'customerNotValidDate' )
    );
// Where Clauses
if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='y' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='n') {  // All Valid Customers. 
    // Apply Filter
    $editor
        ->where('tblCustomers.customerNotValidDate', '', '=' );
} else if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='n' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='y') {  // All Invalid Customers.
    // Apply Filter
    $editor
        ->where( 'tblCustomers.customerNotValidDate', '', '!=' );
} else if (isset($_GET['varCurrentCustomers']) && $_GET['varCurrentCustomers']=='y' && isset($_GET['varInvalidCustomers']) && $_GET['varInvalidCustomers']=='y') {  // All Customers.
    // Apply Filter
    // No Filter
}
// Process Json
$editor
    ->process( $_POST )
    ->json();

我遇到的问题是$ _GET变量重复,因此不应用所需的WHERE子句。下面是参数结果的控制台示例:

  

控制台

gridNumber  3
varCurrentCustomers y
varCurrentCustomers n
varInvalidCustomers y
varInvalidCustomers n

我认为问题涉及尝试将PHP $ _GET参数用作jQuery变量;请告诉我。在这方面的任何帮助表示赞赏。我是一名自学成才的业余网站开发人员。 :)

1 个答案:

答案 0 :(得分:0)

$editor
    ->process($_GET)
    ->json();

缺少"中的值"