A
A
Alex_8x2021-07-06 15:24:31
JavaScript
Alex_8x, 2021-07-06 15:24:31

Why doesn't the .serialize() method work on iPhone?

There is a certain form on the site, the data from which is sent using AJAX.
Form code:

<form id="uni-form-1" class="uni-form" action="unisender.php" method="post" target="_blank">
        <div class="uni-form__title">Заполните форму,<br> чтобы начать консультацию</div>
        <input type="text" id="uni-form__name" name="name" class="form-control" placeholder="Ваше имя" onkeyup="setCapitalLetter(this.value, this)" required="">
        <input type="email" id="uni-form__email" class="form-control" name="email" placeholder="Ваш email" required="">
        <button id="uni-form__send" name="send" class="btn btn-1 uni-form__send"><span>Начать сеанс!</span></button>
        <div class="success-message" style="display: none;" ></div>
        <div class="confidentiality uni-form__text"><span>Я гарантирую Вашу конфиденциальность. Эти данные нужны только для отправки Вам второй сесси Робота-психолога</span></div>
      </form>


JS:
$(function(Subscribe) {
  $('.uni-form').submit(function(e) {
    var $form = $(this);
    $.ajax({
      type: $form.attr('method'),
      url: $form.attr('action'),
      data: $form.serialize()
    }).success(function(){
      console.log('success');
    }).fail(function() {
      console.log('fail');
    });
    //отмена действия по умолчанию для кнопки submit
    e.preventDefault(); 
  });
});


Works everywhere except iPhone. Empirically found out that the problem is in the .serialize() method. The problem is solved if, instead of data: $form.serialize(), send data with the array data: {email: email, name: name}, having previously received the contents of the fields, and writing them to variables.
But I would like to understand why the .serialize() method does not work.

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