开发者

HTTP Request Payload in Sencha Touch FormPanel

开发者 https://www.devze.com 2023-04-10 15:12 出处:网络
I am writing a Sencha Touch app. I have a FormPanel which sends a POST request to the server with Request Payload as follows.

I am writing a Sencha Touch app. I have a FormPanel which sends a POST request to the server with Request Payload as follows.

{
开发者_如何学编程    "records": [
        {
            "Id": 0,
            "Picture": "",
            "PostedOn": "Wed Oct 05 2011 16:06:28 GMT+0600 (QYZT)",
            "OccurringOn": "Wed Oct 05 2011 16:06:28 GMT+0600 (QYZT)",
            "Title": "Test",
            "Organiser": "Umair",
            "Details": "This is test."
        }
    ]
}

How am I supposed to get this data at the server side assuming this is posted to Events.php? I am currently tryong $_POST["Title"] but it is not working.


You have to read the raw post data (either opening the php://input stream or getting from $HTTP_RAW_POST_DATA if it's enabled)


What does print_r($_POST) in events.php show?

You may need to do:

$postvars=json_decode($_POST); // or $postvars=json_decode($_POST['records']);
echo $postvars['records']['title']; // or echo $postvars['title'];

Or similar. I am aware that Sencha frameworks often encode posted vars (though typically not by default for AJAX)


Seems like you are sending json data, so you should use json_decode() on it before trying to access variables.


When you are posting json data from your client then it send request with content type application/json. So nothing will show if you dump $_POST. You need to decode post data using json_decode($_POS['records']). then access your data from the decoded array.


Here is the PHP code you asked for:

<?php
    $records = json_decode($_POST['records']);
    $data = $records->Title
?>

Be sure to properly sanitize anything sent through a POST though before you do something with it as it can be manipulated before it's sent.

0

精彩评论

暂无评论...
验证码 换一张
取 消