Как отключить или скрыть кнопку отправки после проверки формы и отправки ajax? - PullRequest
0 голосов
/ 27 сентября 2018

Нужен скрипт, который disable или hide посылает кнопку после проверки и 100% форму отправляет ajax.

Текущий код:

<script>
    function AjaxFormRequest(result_id,formUkrposhta,url) {
        jQuery.ajax({
            url:url,
            type:"POST",
            dataType:"html",
            data:jQuery("#"+formUkrposhta).serialize(),
            beforeSend: function() {
                $("#messegeUkrResult").html('<span class="wbsn-padding-0">Секунду пожалуйста ...</span>');
                $("#send").prop('disabled', true); // disable button
            },
            success:function(response) {
                $("#send").prop('disabled', false); // enable button
                document.getElementById(result_id).innerHTML = response;

            },
            error: function(response) {
                document.getElementById(result_id).innerHTML = '<p class="wbsn-font-futuranew wbsn-font-20 wbsn-text-deep-orange" style="text-sahdow:0 2px 1px #fff;">Возникла ошибка при заказе. Попробуйте еще раз.</p>';
            }
         });

         $(':input', '#formUkrposhta')
            .not(':button, :submit, :reset, :hidden')
            .val('')
            .removeAttr('checked')
            .removeAttr('selected');
    }
</script>

Но ничего не произошло!И кнопка не disabled после success отправить.Еще больше ... нужна submit кнопка, скрывающаяся после 100% success отправки и после обработки с помощью php-скрипта (не после ошибки или другого) ... Извините за мой плохой английский и большое спасибо всем.Пусть сила будет с тобой!

1 Ответ

0 голосов
/ 27 сентября 2018

Вы можете рассмотреть этот код:

function AjaxFormRequest(result_id,formUkrposhta,url) {
  console.log("Ajax Form Request Triggered.");
  jQuery.ajax({
    url: url,
    type: "POST",
    dataType: "html",
    data: jQuery("#" + formUkrposhta).serialize(),
    beforeSend: function() {
      console.log("Before Send Triggered.");
      $("#messegeUkrResult").html('<span class="wbsn-padding-0">Секунду пожалуйста ...</span>');
      $("#send").prop('disabled', true); // disable button
    },
    success:function(response) {
      console.log("Success Triggered:", response);
      $("#send").prop('disabled', false).hide(); // enable button & Hide it
      $("#" + result_id).html(response);
    },
    error: function(response) {
      console.log("Error Triggered:", response);
      $("#" + result_id).html('<p class="wbsn-font-futuranew wbsn-font-20 wbsn-text-deep-orange" style="text-sahdow:0 2px 1px #fff;">Возникла ошибка при заказе. Попробуйте еще раз.</p>');
    }
  });
  $(':input', '#formUkrposhta')
    .not(':button, :submit, :reset, :hidden')
    .val('')
    .removeAttr('checked')
    .removeAttr('selected');
}

Это добавляет .hide() к кнопке в success.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...