ajax - JQuery return function error catch -
i submitting form call $.ajax() php. here $.ajax function work when success. when want show errors, there trouble loop responsetext. see $.ajax() code:
$.ajax({ // ... , error: function(errors){ $.each(errors, function(index, error){ info.hide().find('ul').append('<li>'+error+'</li>'); }); info.slidedown(); } });
i catch errors, confusion, how renders errors see output in screen http://prntscr.com/7nt3lq. want render these error fields: {"name":["the name field required."],"fname":["the fname field required."]}, if write as:
error: function(errors){ console.log(errors); }
then output in screen http://prntscr.com/7nt9tv. how remove exceptional error: 422 (unprocessable entity) , responsetext loop through?
the problem first param error
callback not respose
data, jqxhr
object.
$.ajax({ url: '/echo/asdf', // ... , error: function (jqxhr) { if (jqxhr.status = 422) { var errors = json.parse(jqxhr.responsetext); $.each(errors, function (index, error) { info.hide().find('ul').append('<li>' + error + '</li>'); }); info.slidedown(); } } });
Comments
Post a Comment