Hey,
i’m currently working on a project, where i have to pass data from a JS client to a CakePHP server.
I’m trying to do this via POST request, but the request isn’t even recevied by the controller.
For this i’m running XAMPP localy on my computer.
In JS: (used absolute path to be absolutly sure, the right function gets called, gonna change that in the end of course)
$.post(‘http://localhost:8008/ersatzteiltool/transferData’, cmd.payload, function(response) {
alert(‘succsess!’)
}, ‘json’);
I’m simply trying to pass some formatted JSON-Data (cmd.payload) to CakePHPs remoterender Controller (using an alternative route see below).
For routing in routes.php
$routes->connect(‘/transferData’, [‘controller’ => ‘remoterender’, ‘action’ => ‘orderSubmit’]);
and in RemoteRenderController.php
public function orderSubmit() {
$this->layout = null;
$jsonData = $this->request->input(‘json_decode’);
//or
//$data = $this->request->getData();
Log::write(‘debug’, 'orderSubmit reached, data: ’ . $jsonData);
}
This way the orderSubmit()-Function isn’t even called. When i change my POST-Request to a GET-Request in JS, the Controller recieves the request, but there is only an empty array passed.
I tried different things already:
- sending not JSON-formatted Data or simple data like
‘data[User][id]’:‘1234’, ‘data[User][name]’:‘John’
(still an empty array arriving with GET, nothing with POST)
- using AJAX POST/GET Request (same result as now)
- tried without using an alternativ route
Anybody got any ideas? Am i just missing the obvious? First time working with Php.
Ideas i had, but couldn’t get working:
- disable cors (maybe its blocking POST-Requests from AJAX?)
Thank you for your help!