I have this simple JSON request
var jsonObject = {apiKey:'123123',method:'asdfsadfasdf',ip:'123.232.123.12'};
$.ajax({
url: "http://api.example.com/users/add",
type: "POST",
data: jsonObject,
dataType: "json",
success: function (result) {
switch (result) {
case true:
alert(result);
break;
default:
break;
}
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
posting to a slim API
$app->post('/add', function () use ($app) {
$user = $app->request->post() ;
$ip = $user['ip'];
$method = $user['method'];
$apiKey = $user['apiKey'];
});
however the alert in the javascript shows 123123 when I return apiKey but other 2 parameters show 'Unexpected token' even though the response in Chrome console shows the correct value.