我已经创建了一个DataTable,我想通过AJAX请求从另一个文件中添加一些数据。
我像这样初始化了我的表:
$urlo = plugin_dir_url(__FILE__) . 'AJAX-ValoriEsecuzioneLogica.php'; // my from where i need to retrieve data for my table
var $j = jQuery.noConflict();
$j(document).ready(function () {
var email = <?php echo json_encode($mail); ?>;
var urlo = <?php echo json_encode($urlo); ?>;
$j('#example1').DataTable({
'paging' : true,
'lengthChange': false,
'searching' : false,
'ordering' : true,
'info' : true,
'autoWidth' : false,
"serverSide": true,
"ajax" : {
"url" : urlo+"?email="email,
"type" : "POST",
"data" : email,
"dataSrc": ""
},
});
});
问题是我没有得到任何结果,但我想将数据附加到我的表中。 我的代码有问题吗?如何通过AJAX调用将数据附加到表?
这是我的php文件,包含返回的数据(我正在使用Wordpress)
$mail = $_GET['email'];
// use this flag to load only wordpress core
$root = $_SERVER['DOCUMENT_ROOT'];
define( 'SHORTINIT', true );
$root= $root.'/wp-load.php';
require ($root);
// now you can use $wpdb
global $table_name, $wpdb;
$table_name = $wpdb->prefix . "bittrex_account_info";
function conta($mail) {
global $wpdb, $table_name;
$attivo = $wpdb->get_var($wpdb->prepare("SELECT attivo FROM $table_name WHERE email = %s", $mail));
$mess = $wpdb->get_var($wpdb->prepare("SELECT messaggio FROM $table_name WHERE email = %s", $mail));
$acquistato = $wpdb->get_var($wpdb->prepare("SELECT acquistato FROM $table_name WHERE email = %s", $mail));
$test_mode = $wpdb->get_var($wpdb->prepare("SELECT test_mode FROM $table_name WHERE email = %s", $mail));
$valoreAttuale = $wpdb->get_var($wpdb->prepare("SELECT valoreAttuale FROM $table_name WHERE email = %s", $mail));
$guadagno = $wpdb->get_var($wpdb->prepare("SELECT guadagno FROM $table_name WHERE email = %s", $mail));
$result = ['acquistato'=>$acquistato,'test_mode'=>$test_mode,'valore_attuale'=>$valoreAttuale,'guadagno'=>$guadagno];
echo json_encode($result);
}
// call the function and pass the parameters
conta($mail);
// close connection
$wpdb->close();
这是我的DataTable(我不会向你展示内部细胞,但只是重要部分):
<table class="table no-margin" id="example1">
<thead>
<tr>
<th>Data</th>
<th>Value</th>
</tr>
</thead>
<tbody id="tabellaAccountBody">
</tbody>
</table>