P
P
Pavel2019-03-18 11:12:11
AJAX
Pavel, 2019-03-18 11:12:11

What is the correct way to use ajax to get json?

jQuery.ajax({
            url: "file.php",
            type: "POST",
            data: $("#form").serialize(),
            dataType: "json",
            success: function (result) {
                if (result) {
                    console.log(result.message);
                } else {
                    alert(result.message);
                }
                return false;
            },
            error: function () {
                console.log("ошибочка, проблема с ajax");
            }

        });

I have such js , how can I get json with data from the form on the server? In the form, the name data is repeated, for example,
input name="name" value="Name of person No. 1"
input name="name" value="Name of person No. 2"
There is a lot of data, ~ 500 inputs

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TCloud, 2019-03-18
@OTCloud

Try wrapping .serialize in JSON.stringify( str )

V
Vadim, 2019-03-18
@supgordan

input name="name[]" value="Name of person #1"
input name="name[]" value="Name of person #2"
And do form serialize

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question