Created
September 20, 2013 10:28
-
-
Save piotr-cz/6635698 to your computer and use it in GitHub Desktop.
Revisions
-
piotr-cz created this gist
Sep 20, 2013 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,64 @@ $.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'); }