我的 WordPress 插件中有许多 php 文件,我遇到问题的主文件中有一个类,我可以在加载显示页面时从中调用一个方法,并且工作正常,但是当我尝试从我的 jQuery 帖子中的第三个文件我得到了问题标题中的错误。据说该错误在该类的文件中,但我看不到错误。我已确保global $wpdb
已将其添加到每个函数中,因此第一个函数可以获取曲目名称,但如果我通过最后一个代码再次调用它作为测试,则不会。任何帮助,将不胜感激。
类文件
<?php
class SelectList
{
public $tableName;
public $driverTableName;
public $classTableName;
public $posTableName;
public $trackTableName;
public function __construct()
{
global $wpdb;
$tableName = $wpdb->prefix . "raceresults";
$driverTableName = $wpdb->prefix . "driverData";
$classTableName = $wpdb->prefix . "classData";
$posTableName = $wpdb->prefix . "posData";
$trackTableName = $wpdb->prefix . "trackData";
}
public function ShowTrack()
{
global $wpdb;
$category = '<option value="0">choose...</option>';
$postids = $wpdb->get_col("SELECT trackName FROM wp_trackData;");
foreach ($postids as $value)
{
$category .= '<option value="' . $value . '">' . $value . '</option>' ;
}
return $category;
}
public function ShowDate($track)
{
global $wpdb;
$type = '<option value="0">choose...</option>';
$postids2 = $wpdb->get_col("SELECT DISTINCT raceDate FROM wp_raceresults WHERE trackName = '" . $track . "';");
foreach ($postids2 as $value2)
{
$type .= "<option>" . $value2 . "</option>";
}
return $type;
}
}
$opt = new SelectList();
jQuery 代码
jQuery(document).ready(function()
{
jQuery("select#kDate").attr("disabled","disabled");
jQuery("select#kTrack").change(function()
{
jQuery("select#kDate").attr("disabled","disabled");
jQuery("select#kDate").html("<option>wait...</option>");
var id = jQuery("select#kTrack option:selected").attr('value');
jQuery.post("<?php echo plugins_url("/race-results/getResults.php"); ?>", {id:id} , function(data)
{
jQuery("select#kDate").removeAttr("disabled");
jQuery("select#kDate").html(data);
})
.success(function() { alert("success"); })
.error(function(xhr, status, detail) { alert("error ("+status+") : " + detail); })
});
});
获取结果
<?php
include "popDrp.php";
echo $opt->ShowDate($_POST[id]);
?>