| Issue 404: | I've added support for JSON based AJAX requests :) | |
| 2 people starred this issue and may be notified of changes. | Back to list |
Hey all,
I've modified the NyroModal to correctly handle JSON Response queries, and
pass it to an object. I've also fixed a bug where the handleError function
was being overridden in the jQuery AJAX instance, due to an extend().
You will need to change debug to false if u want to hide debug.
$.fn.nyroModal.settings = {
debug: true, // Show the debug in the background
It will correctly process the text as JSON, and use the normal error
handlers if it was unable to process it. I.e. it will use contentError and
wrapper etc etc.
Obviously - these changes are very hacky, and I wouldn't recommend putting
them in the main branch, but it's there for anyone that needs it.
Enjoy!
Here is an example of how to use it:
function deleteUserFromResellerConfirm() {
// Grab the default nyro settings
settings = $.fn.nyroModal.settings
// Now modify some of the settings
settings['modal']=true
settings['url']='/api/deleteUserFromReseller';
settings['ajax'] = {
dataType : 'json',
type : 'post',
data : {
reseller_id : reseller_id,
user_id : user_id
}
}
settings['afterJsonSuccess'] = function(data) {
// Okay - display the success message
$.nyroModalRemove()
// Lol
alert(data)
// Execute callback
callback()
}
// Load the modal
$.nyroModalManual(settings);
}
Jan 5, 2010
Sorry - last revision... Added support for HTTP 500 requests too :) handleError needed changing to handleNyroError - otherwise it overwrote the one in jQuery. Quick hack ^_^
Apr 16, 2010
I'm currently thinking of a version 2 of nyroModal and i'll review your code to integrate it in there. Thanks for charing
Status:
Accepted
Labels: Type-Patch |
Hi, Please find an amended version of the above. This one works far better :) Cal New Example Usage: function deleteUserFromResellerConfirm() { // Grab the default nyro settings settings = $.fn.nyroModal.settings // Now modify some of the settings settings['modal']=true settings['url']='/api/deleteUserFromReseller'; settings['ajax'] = { dataType : 'json', type : 'post', data : { reseller_id : reseller_id, user_id : user_id } } settings['afterJsonSuccess'] = function(data) { // Check what the result was if (data.result=='ok') { // Execute callback (global to the scope) callback(); // Fill return $("#deleteUserFromResellerSuccess").html() } else { return false } } // Load the modal $.nyroModalManual(settings); }52.7 KB View Download