A
A
Alexander02017-12-31 09:21:45
PHP
Alexander0, 2017-12-31 09:21:45

Ajax message is not displayed when the form is successfully submitted, what is the reason?

Hello, help me solve the problem: I sent the form via ajax, the form itself is sent, but the message about successful submission is not displayed. What mistake did I make?

$(document).ready(function() {
    $('#form1').submit(function(e) {
   
      var formData = new FormData($('#form1')[0]);
    
      $.ajax({
        url: 'formsend.php',
        data: formData,
        processData: false,
        contentType: false,
        type: 'POST',
        dataType: 'JSON',
        success: function(data) {
alert("Ваше сообщение отпрвлено!");
        }  
      });
      e.preventDefault();
    });
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2019-10-22
@it_pear_yurec

Why not collect an array of categories in the model, where the array of subcategories will be included in the children key? Those. recursively go through all the categories and nest the children in the parent?
Two forich - 1) for the upper categories 2) the second nested for children?

M
marsdenden, 2018-01-04
@marsdenden

judging by this , then something needs to be done with formData. If absolutely certain, then convert to a string, and not send the object as such. Apparently, jQuery is still not smart enough to transform objects. And it doesn't hurt to look at the console (F12 in Firefox/Chrome)
data: JSON.stringify(formData),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question