Added error handling when AJAX response is invalid.
This commit is contained in:
parent
2add111b9b
commit
8878331d3f
3 changed files with 18 additions and 10 deletions
9
js/combined.min.js
vendored
9
js/combined.min.js
vendored
File diff suppressed because one or more lines are too long
10
js/core.js
10
js/core.js
|
@ -7,7 +7,7 @@ $(document).ready(function()
|
|||
}
|
||||
|
||||
// Catches forms being submitted
|
||||
$('form.ajax input[type=submit],form.ajax button.submit').live('click', function()
|
||||
$('form.ajax input[type=submit], form.ajax button.submit').live('click', function()
|
||||
{
|
||||
// Grabs the form
|
||||
var form = $(this).parents('form').get();
|
||||
|
@ -24,7 +24,7 @@ $(document).ready(function()
|
|||
// Forces the cursor to be waiting
|
||||
document.body.style.cursor = 'wait';
|
||||
|
||||
// Copies any CKEditor data to the same named form element (hack)
|
||||
// Copies any CKEditor data to the same named form element (it's a hack!)
|
||||
if (typeof(CKEDITOR) != 'undefined')
|
||||
{
|
||||
if (typeof(CKEDITOR.instances) != 'undefined')
|
||||
|
@ -103,7 +103,13 @@ $(document).ready(function()
|
|||
|
||||
'error': function(XMLHttpRequest, textStatus, errorThrown)
|
||||
{
|
||||
injectMessage(form, errorThrown, 'error');
|
||||
|
||||
// Removes READONLY status
|
||||
$('button, input, textarea', form).attr('readonly', '');
|
||||
|
||||
// Returns the cursor to normal... but is anyone really normal?
|
||||
document.body.style.cursor = 'default';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
9
js/core.min.js
vendored
9
js/core.min.js
vendored
|
@ -1,5 +1,6 @@
|
|||
$(document).ready(function(){jQuery().validate&&$("form").validate();$("form.ajax input[type=submit],form.ajax button.submit").live("click",function(){var a=$(this).parents("form").get();$(".ajax-form-error, .ajax-form-message, label.error",a).fadeOut("normal",function(){$(this).remove()});if(typeof $(a).valid=="undefined"||$(a).valid()==true){$("button, input, textarea",a).attr("readonly","readonly");document.body.style.cursor="wait";if(typeof CKEDITOR!="undefined")if(typeof CKEDITOR.instances!=
|
||||
$(document).ready(function(){jQuery().validate&&$("form").validate();$("form.ajax input[type=submit], form.ajax button.submit").live("click",function(){var a=$(this).parents("form").get();$(".ajax-form-error, .ajax-form-message, label.error",a).fadeOut("normal",function(){$(this).remove()});if(typeof $(a).valid=="undefined"||$(a).valid()==true){$("button, input, textarea",a).attr("readonly","readonly");document.body.style.cursor="wait";if(typeof CKEDITOR!="undefined")if(typeof CKEDITOR.instances!=
|
||||
"undefined")for(var d in CKEDITOR.instances){var c=CKEDITOR.instances[d].getData();c!=""&&$("#"+d).val(c)}d=$(a).attr("method")==""?"GET":$(a).attr("method");c=$(a).attr("action");if(c==""){injectMessage(a,"Form element lacks action attribute","error");$("button, input, textarea",a).attr("readonly","");document.body.style.cursor="default"}else $.ajax({type:d,url:c,data:$(a).serialize(),dataType:"json",success:function(b){if(b.status!="success"&&typeof b.message!="undefined")injectMessage(a,b.message,
|
||||
"error");else if(b.status=="success"){$("input[type=text]",a).val("");$("select",a).val("");$("textarea",a).val("");typeof b.message!="undefined"&&injectMessage(a,b.message,"message");if(typeof b.url!="undefined")parent.location.href=b.url;typeof b.callback!="undefined"&&window[b.callback](b)}else injectMessage(a,b,"error");$("button, input, textarea",a).attr("readonly","");document.body.style.cursor="default"},error:function(){}})}else return false});$("form.ajax").submit(function(){return false});
|
||||
$("table tr:even td").addClass("even");$("table tr:odd td").addClass("odd")});function injectMessage(a,d,c){if(typeof c=="undefined")c="error";switch(c){case "error":var b="#800";break;case "message":b="#080";break;default:b="#000"}c="ajax-form-"+c;b="display:none;color:"+b;$("."+c,a).remove();$(a).prepend('<div class="'+c+'" style="'+b+'" generated="true">'+d+"</div>");$("."+c,a).fadeIn()}function autoTab(a){$(a).val().length>=$(a).attr("maxlength")&&$(a).next().focus()}
|
||||
function disableEnterKey(a){return(window.event?window.event.keyCode:a.which)!=13}function truncate(a,d,c){if(a.length>d)a=c==true?'<span title="'+a+'" style="cursor:help">'+a.substring(0,d)+"...</span>":a.substring(0,d)+"...";return a};
|
||||
"error");else if(b.status=="success"){$("input[type=text]",a).val("");$("select",a).val("");$("textarea",a).val("");typeof b.message!="undefined"&&injectMessage(a,b.message,"message");if(typeof b.url!="undefined")parent.location.href=b.url;typeof b.callback!="undefined"&&window[b.callback](b)}else injectMessage(a,b,"error");$("button, input, textarea",a).attr("readonly","");document.body.style.cursor="default"},error:function(b,f,e){injectMessage(a,e,"error");$("button, input, textarea",a).attr("readonly",
|
||||
"");document.body.style.cursor="default"}})}else return false});$("form.ajax").submit(function(){return false});$("table tr:even td").addClass("even");$("table tr:odd td").addClass("odd")});
|
||||
function injectMessage(a,d,c){if(typeof c=="undefined")c="error";switch(c){case "error":var b="#800";break;case "message":b="#080";break;default:b="#000"}c="ajax-form-"+c;b="display:none;color:"+b;$("."+c,a).remove();$(a).prepend('<div class="'+c+'" style="'+b+'" generated="true">'+d+"</div>");$("."+c,a).fadeIn()}function autoTab(a){$(a).val().length>=$(a).attr("maxlength")&&$(a).next().focus()}function disableEnterKey(a){return(window.event?window.event.keyCode:a.which)!=13}
|
||||
function truncate(a,d,c){if(a.length>d)a=c==true?'<span title="'+a+'" style="cursor:help">'+a.substring(0,d)+"...</span>":a.substring(0,d)+"...";return a};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue