V
V
Vasya2020-02-29 07:27:05
JavaScript
Vasya, 2020-02-29 07:27:05

I want to redirect to the "thank you" page. What's wrong with my JS?

I want to make a redirect to the "thank you" page What's wrong in my JS

This is how it works with the output of text on the screen "Message sent successfully"

// Отправка данных на сервер
$('#form').trigger('reset');
$(function() {
  'use strict';
  $('#form').on('submit', function(e) {
    $('.msg').removeClass('error success');
    $('input').removeClass('inputerror');
    loadanim.play();
    e.preventDefault();
    $.ajax({
      url: 'send.php',
      type: 'POST',
      contentType: false,
      processData: false,
      data: new FormData(this),
      success: function(msg) {
        console.log(msg);
        if (msg == 'ok') {
          $('#form').trigger('reset');
          $('.amount').text('Выберите файлы');
          $('label').removeClass('active');
          $('.msg').text('Сообщение успешно отправлено').addClass('success');
          showmsg.restart();loadanim.duration(0.3).reverse();
        } else {
          if (msg == 'mailerror') {
            $("#email").addClass('inputerror');
          }
          $('.msg').text('Ошибка. Сообщение не отправлено').addClass('error');
          showmsg.restart();loadanim.duration(0.3).reverse();
        }
      }
    });
  });
});


But this does not work with a redirect to a page: hanks.html
// Отправка данных на сервер
$('#form').trigger('reset');
$(function() {
  'use strict';
  $('#form').on('submit', function(e) {
    $('.msg').removeClass('error success');
    $('input').removeClass('inputerror');
    loadanim.play();
    e.preventDefault();
    $.ajax({
      url: 'send.php',
      type: 'POST',
      contentType: false,
      processData: false,
      data: new FormData(this),
      success: function(msg) {
        console.log(msg);
        if (msg == 'ok') {
          $('#form').trigger('reset');
          $('.amount').text('Выберите файлы');
          $('label').removeClass('active');
          $('.msg')window.location.href = "thanks.html"; .addClass('success');
          showmsg.restart();loadanim.duration(0.3).reverse();
        } else {
          if (msg == 'mailerror') {
            $("#email").addClass('inputerror');
          }
          $('.msg').text('Ошибка. Сообщение не отправлено').addClass('error');
          showmsg.restart();loadanim.duration(0.3).reverse();
        }
      }
    });
  });
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2020-02-29
@Dsub92


$('.msg')window.location.href = "thanks.html"; .addClass('success');


What did you expect from this line? Understand JS syntax before writing anything in it.
In your case, this is enough:
if (msg == 'ok') {
    window.location.href = "thanks.html";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question