@sanek3275

Ошибка 400,403 как исправить?

На сайте стоит форма которая добавляет пост на стену.
И все работает, но иногда при добавление комментария или пост, включается вечная загрузка.
62c2c5e54f9f9398108051.jpeg
А в консуле выводиться ошибка.
62c2c5ff84b7f468106528.jpeg
Вывод ошибок на экран плагином buddypress включен. но на экране ошибок нет, только в консоли.

Как найти ошибку и исправить?
Или есть способ настроить , чтоб если в консоли возникала ошибка, скрипт пытался отправить форму снова.

Код отправки формы Jqery
post_data = $.extend( {
        action: 'youzify_post_update',
        'cookie': bp_get_cookies(),
        '_youzify_wpnonce_post_update': $( '#_youzify_wpnonce_post_update' ).val(),
        'content': content,
        'hastag': positiveArr,
        'object': object,
        'item_id': item_id,
        'since': last_date_recorded,
        '_bp_as_nonce': $( '#_bp_as_nonce' ).val() || ''
      }, inputs );
      console.log('post_data');
      console.log(post_data);
      $.post( ajaxurl, post_data, function( response ) {

        form.find( '*' ).each( function() {
          if ( $.nodeName( this, 'textarea' ) || $.nodeName( this, 'input' ) ) {
            $( this ).prop( 'disabled', false );
          }
        });
              if ( form.find( '.youzify-wall-textarea' ).get( 0 ).Youzify_emojioneArea ) {
              	form.find( '.youzify-wall-textarea' ).data( 'Youzify_emojioneArea' ).enable();
              }

            	// Get Response Data.
            	console.log('response');
            	console.log(response);
            	console.log('response.success');
            	console.log(response.success);
            	if ( response.success == false ) {
          $.youzify_DialogMsg( 'error', response.data.error );
        } else {

          // Show Check .
          button.html( '<i class="fas fa-check"></i>' ).hide().fadeIn( 'slow' );

          form.find( '.youzify-delete-attachment' ).trigger( 'click' );

          if ( 0 === $('ul.activity-list').length ) {
            $( 'div.error' ).slideUp( 100 ).remove();
            $( '#message' ).slideUp( 100 ).remove();
            $( 'div.activity').append( '<ul id="activity-stream" class="activity-list item-list">' );
          }

          if ( firstrow.hasClass( 'load-newest' ) ) {
            firstrow.remove();
          }

          $( '#activity-stream' ).prepend( response );

          if ( ! last_date_recorded ) {
            $( '#activity-stream li:first' ).addClass( 'new-update just-posted' );
          }

          // Scroll To Added Post.
          if ( $( response ).get( 0 ) ) {
            $( 'body,html' ).animate({
                scrollTop: $( '#' + $( response ).attr( 'id') ).offset().top - 65 + 'px'
            }, 1000 );
          }

          if ( 0 !== $( '#latest-update' ).length ) {
            var l   = $( '#activity-stream li.new-update .activity-content .activity-inner p' ).html(),
              v     = $( '#activity-stream li.new-update .activity-content .activity-header p a.view' ).attr('href'),
              ltext = $( '#activity-stream li.new-update .activity-content .activity-inner p' ).text(),
              u     = '';

            if ( ltext !== '' ) {
              u = l + ' ';
            }

            u += '<a href="' + v + '" rel="nofollow">' + BP_DTheme.view + '</a>';

            $( '#latest-update' ).slideUp( 300,function() {
              $( '#latest-update' ).html( u );
              $( '#latest-update' ).slideDown( 300 );
            });
          }

          $( 'li.new-update' ).hide().slideDown( 300 );
          $( 'li.new-update' ).removeClass( 'new-update' );
          $( '#whats-new' ).val( '' );

          // Init Slider.
          if ( inputs.post_type == 'activity_slideshow' )  {
            $.youzify_sliders_init();
          }

          // Reset Form.
          form.get( 0 ).reset();

          // Reset Text Form.
                if ( form.find( '.youzify-wall-textarea' ).get( 0 ).Youzify_emojioneArea ) {
                	form.find( '.youzify-wall-textarea' ).get( 0 ).Youzify_emojioneArea.setText( '' );
                }

                // Reset Tagged Users Form.
                form.find( '.youzify-tagged-user .youzify-tagusers-delete-user, .youzify-list-delete-item, .youzify-list-close-icon' ).trigger( 'click' );

                // Select First Element.
                form.find( 'div.youzify-activity-privacy' ).find( '.list div' ).first().trigger( 'click' );
                form.find( '#whats-new-post-in' ).find( 'option' ).first().trigger( 'click' );

                // Update Nice Select.
                if ( ! window.hasOwnProperty( 'youzify_disable_niceselect' ) ) {
                	form.find( '#whats-new-post-in' ).niceSelect( 'update' );
                }

                // Update Post in field.
                $( '#whats-new-post-in' ).trigger( 'change' );

                form.find( '.youzify-wall-options input:radio[name="post_type"]' ).first().trigger( 'change' );
                form.find( '.youzify-lp-prepost .lp-button-cancel' ).trigger( 'click' );

                if ( inputs.post_type == 'activity_giphy' ) {
                	form.find( '.youzify-delete-giphy-item' ).trigger( 'click' );
                	form.find( '.youzify-giphy-submit-search' ).val( '' ).trigger( 'click' );
                }


          // reset vars to get newest activities
          newest_activities = '';
          activity_last_recorded  = 0;

        }
  • Вопрос задан
  • 82 просмотра
Пригласить эксперта
Ответы на вопрос 1
Starina_js
@Starina_js
full-stack web dev
jquery ajax? fetch?
Через что инициализируем отправку?

Если через fetch , то Promise переходит в состояние rejected при ошибке сети или если что-то препятствует завершению запроса. В противном случае наступает состояние resolved, по нему можно смотреть какой ответ.
И если ошибка -> повторяем запрос (Promise#catch)

Если через $.ajax() то на сколько помню, там в error: function () падает. Посмотрите доку.

А вообще надо бы разобраться, почему так происходит, что иногда 400/403 падают, судя по всему с wp чет не фурычит)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
19 апр. 2024, в 03:52
1000 руб./за проект
19 апр. 2024, в 03:01
1000 руб./за проект
18 апр. 2024, в 21:56
2000 руб./за проект