| @@ -65,11 +65,39 @@ | ||
| 65 | 65 | * @param response_data - its object returned from Ajax - class-live-searcg.php |
| 66 | 66 | * @param textStatus - 'success' |
| 67 | 67 | * @param jqXHR - Object |
| 68 | 68 | */ |
| 69 | - function ( response_data, textStatus, jqXHR ) { | |
| 70 | -console.log( ' == Response WPBC_AJX_BOOKING__CREATE == ' ); | |
| 71 | -for ( var obj_key in response_data ){ | |
| 69 | + function ( response_data, textStatus, jqXHR ) { | |
| 70 | + var is_valid_response = ( | |
| 71 | + (typeof response_data === 'object') | |
| 72 | + && (response_data !== null) | |
| 73 | + && (! Array.isArray( response_data )) | |
| 74 | + && Object.prototype.hasOwnProperty.call( response_data, 'resource_id' ) | |
| 75 | + && (typeof response_data[ 'ajx_data' ] === 'object') | |
| 76 | + && (response_data[ 'ajx_data' ] !== null) | |
| 77 | + && (! Array.isArray( response_data[ 'ajx_data' ] )) | |
| 78 | + && (typeof response_data[ 'ajx_data' ][ 'status' ] === 'string') | |
| 79 | + ); | |
| 80 | + | |
| 81 | + if ( ! is_valid_response ) { | |
| 82 | + var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); | |
| 83 | + var jq_node = '#booking_form' + calendar_id; | |
| 84 | + var response_error_message = _wpbc.get_message( 'message_unexpected_server_response' ) || 'The server returned an unexpected response. Please reload the page and try again.'; | |
| 85 | + | |
| 86 | + wpbc_front_end__log_unexpected_ajax_response( 'WPBC_AJX_BOOKING__CREATE', response_data, jqXHR, textStatus, 'Invalid response structure' ); | |
| 87 | + wpbc_front_end__show_message( response_error_message, { 'type' : 'error', | |
| 88 | + 'show_here' : {'jq_node': jq_node, 'where': 'after'}, | |
| 89 | + 'is_append' : true, | |
| 90 | + 'style' : 'text-align:left;', | |
| 91 | + 'content_mode': 'text', | |
| 92 | + 'delay' : 0 | |
| 93 | + } ); | |
| 94 | + wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); | |
| 95 | + return; | |
| 96 | + } | |
| 97 | + | |
| 98 | +console.log( ' == Response WPBC_AJX_BOOKING__CREATE == ' ); | |
| 99 | +for ( var obj_key in response_data ){ | |
| 72 | 100 | console.groupCollapsed( '==' + obj_key + '==' ); |
| 73 | 101 | console.log( ' : ' + obj_key + ' : ', response_data[ obj_key ] ); |
| 74 | 102 | console.groupEnd(); |
| 75 | 103 | } |
| @@ -75,34 +103,8 @@ | ||
| 75 | 103 | } |
| 76 | 104 | console.groupEnd(); |
| 77 | 105 | |
| 78 | 106 | |
| 79 | - // <editor-fold defaultstate="collapsed" desc=" = Error Message! Server response with String. -> E_X_I_T " > | |
| 80 | - // ------------------------------------------------------------------------------------------------- | |
| 81 | - // This section execute, when server response with String instead of Object -- Usually it's because of mistake in code ! | |
| 82 | - // ------------------------------------------------------------------------------------------------- | |
| 83 | - if ( (typeof response_data !== 'object') || (response_data === null) ){ | |
| 84 | - | |
| 85 | - var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); | |
| 86 | - var jq_node = '#booking_form' + calendar_id; | |
| 87 | - | |
| 88 | - if ( '' == response_data ){ | |
| 89 | - response_data = '<strong>' + 'Error! Server respond with empty string!' + '</strong> ' ; | |
| 90 | - } | |
| 91 | - // Show Message | |
| 92 | - wpbc_front_end__show_message( response_data , { 'type' : 'error', | |
| 93 | - 'show_here': {'jq_node': jq_node, 'where': 'after'}, | |
| 94 | - 'is_append': true, | |
| 95 | - 'style' : 'text-align:left;', | |
| 96 | - 'delay' : 0 | |
| 97 | - } ); | |
| 98 | - // Enable Submit | Hide spin loader | |
| 99 | - wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); | |
| 100 | - return; | |
| 101 | - } | |
| 102 | - // </editor-fold> | |
| 103 | - | |
| 104 | - | |
| 105 | 107 | // <editor-fold defaultstate="collapsed" desc=" == This section execute, when we have KNOWN errors from Booking Calendar. -> E_X_I_T " > |
| 106 | 108 | // ------------------------------------------------------------------------------------------------- |
| 107 | 109 | // This section execute, when we have KNOWN errors from Booking Calendar |
| 108 | 110 | // ------------------------------------------------------------------------------------------------- |
| @@ -244,44 +246,31 @@ | ||
| 244 | 246 | |
| 245 | 247 | } |
| 246 | 248 | ).fail( |
| 247 | 249 | // <editor-fold defaultstate="collapsed" desc=" = This section execute, when NONCE field was not passed or some error happened at server! = " > |
| 248 | - function ( jqXHR, textStatus, errorThrown ) { if ( window.console && window.console.log ){ console.log( 'Ajax_Error', jqXHR, textStatus, errorThrown ); } | |
| 250 | + function ( jqXHR, textStatus, errorThrown ) { | |
| 251 | + wpbc_front_end__log_unexpected_ajax_response( 'WPBC_AJX_BOOKING__CREATE', jqXHR.responseText || '', jqXHR, textStatus, errorThrown ); | |
| 249 | 252 | |
| 250 | 253 | // ------------------------------------------------------------------------------------------------- |
| 251 | 254 | // This section execute, when NONCE field was not passed or some error happened at server! |
| 252 | 255 | // ------------------------------------------------------------------------------------------------- |
| 253 | 256 | |
| 254 | - // Get Content of Error Message | |
| 255 | - var error_message = '<strong>' + 'Error!' + '</strong> ' + errorThrown ; | |
| 256 | - if ( jqXHR.status ){ | |
| 257 | - error_message += ' (<b>' + jqXHR.status + '</b>)'; | |
| 258 | - if (403 == jqXHR.status ){ | |
| 259 | - error_message += '<br> Probably nonce for this page has been expired. Please <a href="javascript:void(0)" onclick="javascript:location.reload();">reload the page</a>.'; | |
| 260 | - error_message += '<br> Otherwise, please check this <a style="font-weight: 600;" href="https://wpbookingcalendar.com/faq/request-do-not-pass-security-check/?after_update=10.1.1">troubleshooting instruction</a>.<br>' | |
| 261 | - } | |
| 262 | - } | |
| 263 | - if ( jqXHR.responseText ){ | |
| 264 | - // Escape tags in Error message | |
| 265 | - error_message += '<br><strong>Response</strong><div style="padding: 0 10px;margin: 0 0 10px;border-radius:3px; box-shadow:0px 0px 1px #a3a3a3;">' + jqXHR.responseText.replace(/&/g, "&") | |
| 266 | - .replace(/</g, "<") | |
| 267 | - .replace(/>/g, ">") | |
| 268 | - .replace(/"/g, """) | |
| 269 | - .replace(/'/g, "'") | |
| 270 | - +'</div>'; | |
| 271 | - } | |
| 272 | - error_message = error_message.replace( /\n/g, "<br />" ); | |
| 257 | + var error_message = _wpbc.get_message( 'message_unexpected_server_response' ) || 'The server returned an unexpected response. Please reload the page and try again.'; | |
| 258 | + if ( jqXHR.status ){ | |
| 259 | + error_message += ' (' + parseInt( jqXHR.status, 10 ) + ')'; | |
| 260 | + } | |
| 273 | 261 | |
| 274 | 262 | var calendar_id = wpbc_get_resource_id__from_ajx_post_data_url( this.data ); |
| 275 | 263 | var jq_node = '#booking_form' + calendar_id; |
| 276 | 264 | |
| 277 | 265 | // Show Message |
| 278 | - wpbc_front_end__show_message( error_message , { 'type' : 'error', | |
| 279 | - 'show_here': {'jq_node': jq_node, 'where': 'after'}, | |
| 280 | - 'is_append': true, | |
| 281 | - 'style' : 'text-align:left;', | |
| 282 | - 'delay' : 0 | |
| 283 | - } ); | |
| 266 | + wpbc_front_end__show_message( error_message , { 'type' : 'error', | |
| 267 | + 'show_here' : {'jq_node': jq_node, 'where': 'after'}, | |
| 268 | + 'is_append' : true, | |
| 269 | + 'style' : 'text-align:left;', | |
| 270 | + 'content_mode': 'text', | |
| 271 | + 'delay' : 0 | |
| 272 | + } ); | |
| 284 | 273 | // Enable Submit | Hide spin loader |
| 285 | 274 | wpbc_booking_form__on_response__ui_elements_enable( calendar_id ); |
| 286 | 275 | } |
| 287 | 276 | // </editor-fold> |