Skip to content

Instantly share code, notes, and snippets.

@piotr-cz
Created September 20, 2013 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotr-cz/6635698 to your computer and use it in GitHub Desktop.
Save piotr-cz/6635698 to your computer and use it in GitHub Desktop.
Test usage of [com_ajax](https://github.com/joomla/joomla-cms/pull/1960). Please note I don't know how the jQuery response looks like, this is based on guess.
$.ajax({
type : 'POST',
data : request,
// Got HTTP response code 200
success: function (response)
{
switch (this.data.request.format)
{
// Handling JSON format
case 'json':
if (response.success)
{
// Do something with response.data
}
else
{
/* We got here because:
* a) developer didn't use proper query string
* b) called module/ plugin threw and exception
*
* Error message for debugging is in response.error.message;
*/
alert('Contact developer of this extension');
}
// There are some messages to show
if (response.messages)
{
Joomla.renderMessages(reponse.messages);
}
break;
case 'raw':
// Update the element with received data
break;
case 'image':
// Update the image with received data blob
break;
case 'xml':
// Parse XML
break;
default:
// This extension cannot handle other formats.
break;
}
}
// Any format but JSON
/* We got here because
* a) developer didn't use proper query string
* b) called module/ plugin threw and exception
*
* Error message for debugging is in response.responseText.
* Additionally may check for HTTP status code: response.responseCode
*/
error: function(response)
{
alert('Contact developer of this extension');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment