Please assist. I’ve a easy plugin which makes use of ajax name. After I name one other perform inside ajax php perform (within the under instance I’m calling get_cat() perform from update_passage_list() perform) I get “Didn’t load useful resource: the server responded with a standing of 500 (Inner Server Error)” error.
quiz.js:
$jq =jQuery.noConflict();
$jq(doc).prepared(perform($jq) {
update_passage_list(32);
});
var update_passage_list = perform(id){
$jq.submit(quiz.ajaxURL, {
motion:"update_passage_list",
nonce:quiz.quizNonce,
cpid : id
}, perform(return_data) {
alert('Return Knowledge = ' + return_data);
}, "json");
};
index.php:
<?php
/*
Plugin Title: WP Quiz
Plugin URI: -
Description: Plugin description.
Creator: Creator Title
Model: 1.0
Creator URI: url
*/
class WP_Quiz {
public $plugin_url;
public perform __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'));
}
perform 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 perform get_cat($id) {
$new_id = $id + 100;
return $new_id;
}
perform update_passage_list() {
$cpid = $_POST['cpid'];
$cpid = get_cat($cpid);
echo $cpid;
die();
}
}
$quiz = new WP_Quiz();