javascript - jquery ajax response error not working -
i have ajax call api return correctly (200) when url , parameters fine. trying force error bad request. console inform me error code 400 never seems error method. instead gets stuck in jquery line , never returns.
fetch: function(successcallback, errorcallback) { var apiurl = this.applyfilter(filters); var self = this; this.log('fetch', apiurl, currentsearchmode); $.ajax({ url: apiurl, type: 'get', cache: (debug) ? true: false, processdata: true, crossdomain: true, scriptcharset: 'utf-8', jsonp: 'callback', datatype: 'jsonp', success: function(data, statustext, jqxhr) { console.log(jqxhr); // if(jqxhr.status == 400){ // console.log('there error'); // } self.log('fetch::success', data); if (typeof data.error !== 'undefined') { shownoresulterror = true; var appdata = lastvalidresult[currentsearchmode]; } else { shownoresulterror = false; var appdata = self.normalize[currentsearchmode](self, data); lastvalidresult[currentsearchmode] = appdata; } if (typeof successcallback === 'function') successcallback(appdata); }, error: function(jqxhr, textstatus, errorthrown) { //do sth here // if(jqxhr.status&&jqxhr.status==400){ // alert(jqxhr.responsetext); // }else{ // alert("something went wrong"); // } // console.log('works now'); // self.log('fetch::error', textstatus, errorthrown); // if (typeof errorcallback === 'function') // errorcallback.apply(this, arguments); }, complete: function(jqxhr, textstatus) { console.log(jqxhr); console.log('complete'); } }); },
so image shows gets stuck. can catch complete , success functions when there 400 response there nothing happening. tried anything, done(), fail() since assumed there might problem deprecated behavior. same problem there. can help, please?
try:
fetch: function(successcallback, errorcallback) { var apiurl = this.applyfilter(filters); var self = this; this.log('fetch', apiurl, currentsearchmode); $.ajax({ url: apiurl, type: 'get', cache: (debug) ? true: false, processdata: true, crossdomain: true, scriptcharset: 'utf-8', jsonp: 'callback', datatype: 'jsonp', success: function(data, statustext, jqxhr) { console.log(jqxhr); // if(jqxhr.status == 400){ // console.log('there error'); // } self.log('fetch::success', data); if (typeof data.error !== 'undefined') { shownoresulterror = true; var appdata = lastvalidresult[currentsearchmode]; } else { shownoresulterror = false; var appdata = self.normalize[currentsearchmode](self, data); lastvalidresult[currentsearchmode] = appdata; } if (typeof successcallback === 'function') successcallback(appdata); }, error: function(data){ console.log(data); console.log(data.responsetext); }, complete: function(jqxhr, textstatus) { console.log(jqxhr); console.log('complete'); } }); },
then, show me what's in console
Comments
Post a Comment