M
M
Morfeey2017-12-22 11:45:22
PHP
Morfeey, 2017-12-22 11:45:22

The $_POST array is not filled, what should I do?

There is a quite ordinary ajax request:

$.ajax({
                        url: "API",
                        type: "POST",
                        dataType: "html",
                        data: ({json: JSON.stringify({language: {func: "setLang", args: ["hjg"]}}) }),
                        beforeSend: function () {
                          $("div").html("1 sec");  
                        },
                        success: function (data) {
                            $("div").html(data);
                        }
                    });

We accept on the server, but it's empty there. We change the request type to GET and everything is in order.
Googling found only that there may be a problem in php ini, looked, corrected, rebooted - zero effect.
I use: OpenServer 5.2.2 and php7.1.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Morfeey, 2017-12-22
@Morfeey

Trouble found. The GET method - it turned out to be all the same to the address, unlike POST.
For GET address: "API" is valid. For POST, you need to specify "/" additionally.

A
Alexander Aksentiev, 2017-12-22
@Sanasol

type: "GET",

It's also better to write method rather than type.
some kind of porridge baby.
or JSON normally do or send a regular array/object.
In JSON, php does not understand so-and-so by itself.

S
Sergey Bard, 2017-12-22
@serg_small_developer

$.ajax({
            type: 'POST',
            url: 'url',
            data:{
                func: func,
                args: hjg
            }
        })
        .done(function(data) {
                 $("div").html(data);
        })

do it just like that

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question