A
A
Andrey Glukhovskoy2021-12-16 19:13:04
JavaScript
Andrey Glukhovskoy, 2021-12-16 19:13:04

How to fix form submit script for IE11?

What error is present here? Why does this script not work in IE11, provided that it does not produce errors. The handler is working, works on normal browsers. Thanks in advance.

$(document).on("submit", "form", function () {
    var form = $(this);

    if (form[0].hasAttribute("not-ajax")) {
    } else {
      var gateway = "/local/ajax/form.php";
      var data = form.serialize();
      var xhr;

      if (xhr && xhr.readyState != 4) {
        xhr.abort();
      }

      xhr = $.ajax({
        type: "POST",
        url: gateway,
        data: data,
        success: function success(res) {
          if (res == "Y") {
            clearForm(form);
            popupClose();
            popupOpen("aplicpopup", "");
          } else {
            if (res == "step") {
              $from = $(".hero-services__form [name=FROM]").val();
              $to = $(".hero-services__form [name=TO]").val();
              $weight = $(".hero-services__form [name=WEIGHT]").val();
              $volume = $(".hero-services__form [name=VOLUME]").val();
              $width = $(".hero-services__form [name=WIDTH]").val();
              $length = $(".hero-services__form [name=LENGTH]").val();
              $height = $(".hero-services__form [name=HEIGHT]").val();

              if (!$volume && $width && $length && $height) {
                $volume =
                  parseFloat($width) *
                  parseFloat($length) *
                  parseFloat($height);
              }

              if (!$volume) {
                alert("Укажите объем или габариты!");
              } else {
                var _data = {
                  FROM: $from,
                  TO: $to,
                  WEIGHT: $weight,
                  VOLUME: $volume
                };
                $.ajax({
                  type: "POST",
                  url: "/local/ajax/calc.php",
                  dataType: "json",
                  data: _data,
                  success: function success(result) {
                    if (result.success === true) {
                      $(".popup-callback [name=FROM]").val($from);
                      $(".popup-callback [name=TO]").val($to);
                      $(".popup-callback [name=WEIGHT]").val($weight);
                      $(".popup-callback [name=VOLUME]").val($volume);
                      $(".popup-callback [name=WIDTH]").val($width);
                      $(".popup-callback [name=LENGTH]").val($length);
                      $(".popup-callback [name=HEIGHT]").val($height);

                      if (result.avia_price) {
                        $("#avia-sum").text(result.avia_price + " руб");
                        $("#avia-sum").parent().show();
                      } else {
                        $("#avia-sum").parent().hide();
                      }

                      if (result.zd_price) {
                        $("#gd-sum").text(result.zd_price + " руб");
                        $("#gd-sum").parent().show();
                      } else {
                        $("#gd-sum").parent().hide();
                      }

                      if (result.auto_price) {
                        $("#avto-sum").text(result.auto_price + " руб");
                        $("#avto-sum").parent().show();
                      } else {
                        $("#avto-sum").parent().hide();
                      }

                      clearForm(form);
                      inputDefault();
                      popupOpen("callback", "");
                    } else {
                      alert(result.message);
                    }
                  }
                });
              }
            } else {
              form.replaceWith(res);
              $(".phone").inputmask("+7(999) 999 9999", {
                clearIncomplete: true,
                clearMaskOnLostFocus: true
              });
            }
          }
        },
        error: function error(res) {
          console.log(res);
        }
      });
      return false;
    }
  });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question