请帮忙。我有一个使用ajax调用的简单插件。当我调用ajax php函数中的另一个函数时(在下面的示例中,我从update\\u passage\\u list()函数调用get\\u cat()函数),我得到了“加载资源失败:服务器响应状态为500(内部服务器错误)”的错误。
测验。js公司:
$jq =jQuery.noConflict();
$jq(document).ready(function($jq) {
update_passage_list(32);
});
var update_passage_list = function(id){
$jq.post(quiz.ajaxURL, {
action:"update_passage_list",
nonce:quiz.quizNonce,
cpid : id
}, function(return_data) {
alert(\'Return Data = \' + return_data);
}, "json");
};
索引。php:
<?php
/*
Plugin Name: WP Quiz
Plugin URI: -
Description: Plugin description.
Author: Author Name
Version: 1.0
Author URI: url
*/
class WP_Quiz {
public $plugin_url;
public function __construct() {
$this->plugin_url = plugin_dir_url(__FILE__);
add_action(\'admin_enqueue_scripts\', array($this, \'wpq_admin_scripts\'));
add_action(\'wp_ajax_nopriv_update_passage_list\', array($this, \'update_passage_list\'));
add_action(\'wp_ajax_update_passage_list\', array($this, \'update_passage_list\'));
}
function wpq_admin_scripts() {
wp_enqueue_script(\'jQuery\');
wp_register_script(\'quiz-admin\', plugins_url(\'js/quiz.js\', __FILE__), array(\'jquery\'));
wp_enqueue_script(\'quiz-admin\');
$config_array = array(
\'ajaxURL\' => admin_url(\'admin-ajax.php\'),
\'quizNonce\' => wp_create_nonce(\'quiz-nonce\'),
\'plugin_url\' => $this->plugin_url
);
wp_localize_script(\'quiz-admin\', \'quiz\', $config_array);
}
public function get_cat($id) {
$new_id = $id + 100;
return $new_id;
}
function update_passage_list() {
$cpid = $_POST[\'cpid\'];
$cpid = get_cat($cpid);
echo $cpid;
die();
}
}
$quiz = new WP_Quiz();