Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ==with response codes==
- function errorHandler( xhr, status, data ) {
- if( status === 500 ) {
- reportMessage( 'There was problem with server' );
- } else if( status === 200 ) {
- if( typeof data === 'string' ) {
- data = JSON.stringify( data );
- }
- // inspect the data and work out the problem
- }
- }
- $.ajax({
- url: '/api.php...',
- success: function( data, status, xhr ) {
- if( data.error ) {
- errorHandler( xhr, status, data );
- } else {
- // success handler
- }
- },
- error: errorHandler
- })
- ==without response codes==
- function errorHandler( xhr, status, data ) {
- data = JSON.stringify( data );
- if( status === 500 ) {
- reportMessage( 'There was problem with server' );
- } else if( status === 404 ) {
- reportMessage( 'response not found' );
- } else if( status === 400 ) {
- reportMessage( 'problem with parameters' );
- // dive into data to see what problem is
- }
- }
- $.ajax({
- url: '/api.php...',
- success: function( data, status, xhr ) {
- // success handler
- },
- error: errorHandler
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement