Hello everyone,
I'm currently working on "Adding/updating course modules without page reload", that is to say, using ajax to load and update course's module. The problem is after a course module has been added/updated, I have to use ajax request to load and display the whole course again. To do this, I have to move code in course/view.php into function get_course_content() so that this function can be called by normal request as well as ajax request. For normal request, function get_course_content () works fine, but for ajax request, get_course_content() does not work. I know the problem comes from the fact that $OUTPUT->header() can only be called once.
Here's the code that handles ajax request (from file course/rest.php):
echo $OUTPUT->header(); // send ajax headers
switch($requestmethod) {
case 'GET':
switch($class){
case 'view': {
$html = get_course_content($courseId);
echo json_encode(array('html' => $html));
}
break;
}
break;
case 'POST':
....
}
And here's how function get_course_content() looks like:
function get_course_content($courseId){
global $OUTPUT;
$html= $OUTPUT->header();
//here will be some course modules rendering
$html .= $OUTPUT->footer();
return $html;
}
I want to ask if there's any method to fix it ?
Any help is appreciated.