Created
September 20, 2013 10:28
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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