Backend Ajax protocol: Difference between revisions
From LimeSurvey Manual
No edit summary |
No edit summary |
||
Line 5: | Line 5: | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
{ | { | ||
result: mixed | result: mixed, | ||
error: {code: int, message: string} | error: {code: int, message: string}, | ||
loggedIn: boolean, | |||
permission: boolean, | |||
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Of course there needs to be server side support for this protocol, too, with helper functions to output correct JSON code, e.g. <code>Ajax::outputResult<code> or <code>Ajax::outputError($code, $message)</code>. | Of course there needs to be server side support for this protocol, too, with helper functions to output correct JSON code, e.g. <code>Ajax::outputResult<code> or <code>Ajax::outputError($code, $message)</code>. |
Revision as of 12:04, 8 August 2016
There should be a standard JSON protocol between the LS backend and Ajax calls to check for errors, permissions and if the user still is logged in. A suggestion would be to wrap $.ajax
in a function that checks this for you, like $.lsAjax
.
All server Ajax calls must return a JSON in the following format:
{
result: mixed,
error: {code: int, message: string},
loggedIn: boolean,
permission: boolean,
}
Of course there needs to be server side support for this protocol, too, with helper functions to output correct JSON code, e.g. Ajax::outputResult
or
Ajax::outputError($code, $message)
.