POST does not arrive on the server

POST does not arrive on the server

Chris4712Chris4712 Posts: 11Questions: 2Answers: 0

Hello together!

I create my data on the server and return a JSON array (iPad_infos.php). This works!
Now when I want to send input fields of a form to my iPad_infos.php file, I do it like this:

    "ajax": {
      "url": "/modules/ipads/_functions/iPad_infos.php",
      "type"   : "POST",
      "data"   : function ( d ) {
        return $('#FilterForm').serialize();
      },
      "dataType": "json",
      "dataSrc": "",
      "cache": false,
      "contentType": "application/json; charset=utf-8"
    },

In the Firefox console I can also see "Type=WiFi&Owner=true" on request. So far good.

But when I want to read the value of Type or Owner in my iPad_infos.php with $_POST["Type"] or $_POST["Owner"], the variables are not there!

When I call the iPad_infos.php from another AJAX request, I can read the passed values without problems.

Where is my error?

Greetings!

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    You could try adding both those values separately, like one of the first two examples on ajax.data. Could you try that please, and see if any success,

    Colin

  • Chris4712Chris4712 Posts: 11Questions: 2Answers: 0
    edited February 2021

    Hey Colin!

    I have tried this:

            "ajax": {
              "url": "/modules/ipads/_functions/iPad_infos.php",
              "type"   : "POST",
              "data": {
                "user_id": 451
            },
              "dataType": "json",
              "dataSrc": "",
              "cache": false,
              "contentType": "application/json; charset=utf-8"
            },
    

    (i.e. as in the example).

    According to the Firefox Web Console, this is also transmitted (request content "user_id=451").

    in my ipad_infos.php I have the following:

            echo "Value POST: ";
            echo $_POST["user_id"];
            echo "<br>";
            echo "Value GET: ";
            echo $_GET["user_id"];
            echo "<br>";
            var_dump($_POST);
            echo "<br>";
            var_dump($Request);
            echo "<br>";
    

    And get as response:
    Value POST:
    GET value:
    array(0) { }
    NULL

    I just don't understand it!

  • Chris4712Chris4712 Posts: 11Questions: 2Answers: 0

    I made it work!!!

     `"contentType": "application/json; charset=utf-8"`
    

    Was the error. After I took it out of the JS it worked!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    Answer ✓

    Ah, good find! Thanks for reporting back,

    Colin

This discussion has been closed.