MDL-23739 improved ajax headers - now using application/json with the exception of YUI upload

This commit is contained in:
Petr Skoda 2010-08-10 08:50:08 +00:00
parent 09e8e6d408
commit bce08d9a37
7 changed files with 31 additions and 4 deletions

View File

@ -40,6 +40,8 @@ $content = optional_param('content', '', PARAM_RAW);
$itemid = optional_param('itemid', '', PARAM_INT);
$page = optional_param('page', 0, PARAM_INT);
echo $OUTPUT->header(); // send headers
// initilising comment object
if (!empty($client_id)) {
$args = new stdclass;

View File

@ -51,6 +51,8 @@ require_login($course);
require_capability('moodle/course:enrolreview', $context);
require_sesskey();
echo $OUTPUT->header(); // send headers
$manager = new course_enrolment_manager($course);
$outcome = new stdClass;

View File

@ -33,6 +33,8 @@ $action = optional_param('action', 'list', PARAM_ALPHA);
require_login();
echo $OUTPUT->header(); // send headers
$err = new stdclass;
if (isguestuser()) {
$err->error = get_string('noguest');

View File

@ -2593,18 +2593,36 @@ class core_renderer_ajax extends core_renderer {
$e->stacktrace = format_backtrace($backtrace, true);
}
}
@header('Content-type: application/json');
$this->header();
return json_encode($e);
}
public function notification($message, $classes = 'notifyproblem') {
}
public function redirect_message($encodedurl, $message, $delay, $debugdisableredirect) {
}
public function header() {
// unfortunately YUI iframe upload does not support application/json
if (!empty($_FILES)) {
@header('Content-type: text/plain');
} else {
@header('Content-type: application/json');
}
/// Headers to make it not cacheable and json
@header('Cache-Control: no-store, no-cache, must-revalidate');
@header('Cache-Control: post-check=0, pre-check=0', false);
@header('Pragma: no-cache');
@header('Expires: Mon, 20 Aug 1969 09:23:00 GMT');
@header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
@header('Accept-Ranges: none');
}
public function footer() {
}
public function heading($text, $level = 2, $classes = 'main', $id = null) {
}
}

View File

@ -10,6 +10,8 @@ $displayformat = optional_param('displayformat',-1, PARAM_SAFEDIR);
$popup = optional_param('popup',0, PARAM_INT);
$ajax = optional_param('ajax',0, PARAM_INT);
//TODO: do not make combined ajax+normal scripts (skodak)
if ($ajax && !defined('AJAX_SCRIPT')) {
define('AJAX_SCRIPT', true);
}
@ -78,6 +80,7 @@ if ($entries) {
}
if ($ajax) {
echo $OUTPUT->header(); // send headers
$result = new stdClass;
$result->success = true;
$result->entries = $entries;

View File

@ -42,6 +42,8 @@ $filepath = optional_param('filepath', '/', PARAM_PATH);
$user_context = get_context_instance(CONTEXT_USER, $USER->id);
echo $OUTPUT->header(); // send headers
//
//NOTE TO ALL DEVELOPERS: this script must deal only with draft area of current user, it has to use only file_storage and no file_browser!!
//

View File

@ -56,9 +56,7 @@ list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
$PAGE->set_context($context);
/// Headers to make it not cacheable
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
echo $OUTPUT->header(); // send headers
if (!confirm_sesskey()) {
$err->error = get_string('invalidsesskey');