Home » Php » php – jQuery ajax back to $_POST instead of REQUEST payload

php – jQuery ajax back to $_POST instead of REQUEST payload

Posted by: admin July 12, 2020 Leave a comment


I remember I using the jQuery ajax post last year and i could simply get the post data by typing $_POST['param']. Today I am using it again for a project so I loaded the latest jQuery lib and used the following code:

<script type="text/javascript">
    $(document).on('submit', '.ajaxform', function(e){

        var datastring = $(this).serialize();

            type: "POST",
            data: datastring,
            contentType: "application/json; charset={CHARSET}",
            dataType: "json",
            beforeSend: function(){
            success: function(data){
            error: function(errMsg){
<form action="" id="register" name="register" class="ajaxform" method="post" enctype="multipart/form-data">

    <input type="text" name="username" value="" />
    <input type="password" name="password" value="" />

    <input type="hidden" name="action" value="register" />
    <input type="hidden" name="{TOKENID}" value="{TOKEN}" />

    <input type="submit" value="Register" />


After I submit, I can’t get the input field value by typing $_POST['username'].

I checked the inspect element, and I noticed that something is different.

Request URL:http://project0/member.php
Request Method:POST
Status Code:200 OK
Content-Type:application/json; charset=UTF-8
Request payload:

Is that why i can’t get the POST data by simply typing $_POST['param']? How do I go back to POST data and not the payload?

How to&Answers:


contentType: "application/json; charset={CHARSET}"

Use(default value of content type):

contentType: "application/x-www-form-urlencoded; charset=UTF-8"