Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-72080

Content-Type wrong for core_get_fragment

XMLWordPrintable

      In response to the XHR request to core_get_fragment the Moodle response has HTTP header Content-Type set to "text/html; charset=utf-8". But this function returns JSON so presumably the MIME type should be "application/json".

      This causes an error in Moodle if there's some HTML processing between the web server and the browser, for example Apache's mod_proxy_html. Moodle sends JSON in reply to core_get_fragment:

      [{"error":false,"data":{"html":...

      But the HTML proxy sees the "text/html" MIME type and processes the output so it becomes:

      <html><body><p>[{"error":false,"data":{"html":...

      Obviously this is no longer JSON so in the browser you get an error: JSON.parse: unexpected character at line 1 column 1 of the JSON data. This thread is an example of this issue.

      To reproduce the problem

      (These steps shows the incorrect MIME type, not the HTML proxy issue resulting in the above error message).

      1. In Moodle go to the Participants page of a course.
      2. In your browser open the developer tools and switch to the network monitor.
      3. Click Enrol users.
      4. In the network monitor click on the request /lib/ajax/service.php?sesskey=...&info=core_get_fragment. Examine the response headers and check the Content-Type header.

            pholden Paul Holden
            leonstr Leon Stringer
            Tim Hunt Tim Hunt
            Jun Pataleta Jun Pataleta
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            4 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 20 minutes
                20m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.