Вот моя функция js < /p>
Код: Выделить всё
function courseGradeHistory(student_id) {
// Ensure jQuery is available
if (typeof jQuery === 'undefined') {
console.error('jQuery is not defined. Please ensure jQuery is loaded before this script.');
return;
}
// Get the course code and student ID from the input fields
var course_code = document.getElementById("course_code").value;
var $resultsContainer = $('#studentCourseSchedule');
var student_id = student_id || document.getElementById("student_id").value;
console.log("Course Code: " + course_code);
console.log("Student ID: " + student_id);
// Validate inputs
if (!student_id || !course_code) {
alert("Please provide both Student ID and Course Code.");
return;
}
alert("Loading Course History for Student ID: " + student_id + " and Course Code: " + course_code);
$resultsContainer.html('
Loading Courses...
');
// Make the AJAX request to fetch course grade history
// Ensure that 'ajaxurl' is defined in your WordPress environment
$.ajax({
url: ajaxurl,
type: 'POST',
data: {
action: 'connect_course_history',
student_id: student_id,
course_code: course_code,
numberofdays: 30 // You can adjust this value as needed
},
success: function(data) {
$resultsContainer.html(data);
},
error: function(xhr, status, error) {
$resultsContainer.html('
Error loading courses. Please try again.
');
console.error('AJAX Error:', status, error);
}
});
}
// Зарегистрировать действие Ajax для аутентифицированных пользователей
add_action ('wp_ajax_connect_course_history', 'connect_course_history');
// Зарегистрируйте действие ajax для unaustory '); /> add_action ('wp_ajax_nopriv_connect_course_history', 'connect_course_history'); < /p>
Код: Выделить всё
function connect_course_history($student_id, $course_code, $numberofdays) {
global $wpdb;
$sql = "CALL sp_connect_course_history('$student_id', '$course_code', $numberofdays);";
$wpdb->query($sql);
$course_history = $wpdb->get_results($sql, ARRAY_A);
if (empty($course_history)) {
return "
No course history found for this student.
";
}
// Prepare the output
$output = "DATEGrade";
foreach ($course_history as $course) {
$output .= "";
$output .= "{$course['DATE']}";
$output .= "{$course['grade']}";
$output .= "";
}
$output .= "";
return $output;
}
< /code>
это все, что я вижу в консоли разработчика < /p>
error @ myplugin_script.js:63
c @ jquery.min.js?ver=3.7.1:2
fireWith @ jquery.min.js?ver=3.7.1:2
l @ jquery.min.js?ver=3.7.1:2
(anonymous) @ jquery.min.js?ver=3.7.1:2
XMLHttpRequest.send
send @ jquery.min.js?ver=3.7.1:2
ajax @ jquery.min.js?ver=3.7.1:2
(anonymous) @ jquery-migrate.min.js?ver=3.4.1:2
e. @ jquery-migrate.min.js?ver=3.4.1:2
courseGradeHistory @ myplugin_script.js:48
onchange @ ?page_id=1238&student_id=954894:516
handleMouseUp_ @ unknown
Подробнее здесь: https://stackoverflow.com/questions/796 ... -container
Мобильная версия