Retrieving POST Data from AJAX Call to PHP

后端 未结 3 2069
我寻月下人不归
我寻月下人不归 2021-01-02 05:06

Three days had passed and still having problems to get this things work. This AJAX Call on my js file seems working when it comes to sending JSON data:

 var         


        
相关标签:
3条回答
  • 2021-01-02 05:40

    instead of this

    data: "{'lastName':'" + _lname + "','firstName':'" + _fname +
    "','middleName':'" + _mname + "'}",
    

    use this

    data: {lastName:_lname,firstName:_fname,middleName:_mname},
    
    0 讨论(0)
  • 2021-01-02 05:42

    Can you see the ajax request data using the firebug console?

    You cannot get the lastname, firstname from $_POST. It's inside the json string. First, you have to get the data using

     $data = $_POST['data'] or $_REQUEST['data']
    

    Then, decode the $data using json_deocde and access your attributes.

    json_decode($data);
    
    0 讨论(0)
  • 2021-01-02 05:49
    $post = file_get_contents('php://input');
    
    0 讨论(0)
提交回复
热议问题