jeudi 11 décembre 2014

Model/Store.save() solution via Request Body (when not working with regular request)

Hi guys,

just wanted to share something I found out today. I wondered why I wasn't able to get the simple model.save() function working with my server. When sending an Ajax request with form-data manually everything worked fine. But as soon I used model.save() (which uses the Rest proxy) my server didn't receive any model data in the PHP $_REQUEST variable.


Now I found out that model.save() sends the data within the REQUEST BODY (which is called Request Payload in the Chrome console). This may depend on the server, don't know.


Instead of using $_REQUEST in your PHP Script you have to get the JSON data via file_get_contents('php://input') and the convert it to an array.



Code:



$json_data = file_get_contents('php://input');
$data_array = json_decode($json_data);

Find a great example with code here:

http://ift.tt/1wBkhz6

There's also a PHP function called http_get_request_body(), which may do the same, but I didn't test it yet.


Definitely miss this info in the Sencha docs, as there's no single word about request body!






Model/Store.save() solution via Request Body (when not working with regular request)

Aucun commentaire:

Enregistrer un commentaire