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

[META] Convert AJAX scripts not using AJAX_SCRIPT

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.3.4, 2.7.3, 2.8.1, 2.9
    • Fix Version/s: STABLE backlog
    • Component/s: JavaScript
    • Labels:
    • Affected Branches:
      MOODLE_23_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE, MOODLE_29_STABLE

      Description

      I've noticed a couple of scripts recently which aim to render both HTML, and JSON in one script rather than splitting out the HTML to one script, and JSON to another.
      So far I think that they've all (I think there's a whole two) taken the 'ajax' parameter. If it's set then they return json instead of html.

      However, because AJAX_SCRIPT has to be defined before config.php is included and the page is setup, any exceptions which may be thrown would not be wrapped in JSON but use the standard HTML output.

      There are two possible solutions that I can see:

      • split out all scripts into two; or
      • set AJAX_SCRIPT to true in lib/setup.php if a truthful AJAX parameter was sent.

      The second option feels much dirtier - what if someone calls their field json instead of ajax for example, or what if ajax was the name of a variable on the page for some other reason?

      If we go for the option of splitting them out, then I think that we should standardise on a naming scheme for such things to indicate the purpose.

      Mahara have standardised on a scheme I personally quite like:
      Standard script: foo.php
      AJAX script: foo.ajax.php

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              dobedobedoh Andrew Nicols
              Participants:
              Component watchers:
              Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated: