i am trying to post data using axios. i can get the api call to work but the problem i have is processing the data on the server side. the normal $_POST
paramater in php is empty.
I have the following action
export const UPDATE_CONTENT = 'update_content';
export function updateContent(values) {
console.log(values);
let obj = {};
obj['params'] = values;
console.log(obj);
const request = axios.post(`/api/admin/rename/content/management/format/json`,JSON.stringify(values));
return {
type: UPDATE_CONTENT,
payload: request
};
}
values
is a key value object
{content : "<p>html text</p>",id:"21"}
when i post the using like axios.post(
url,values);
the request parameter is shown as payload and the $_POST
on server side is empty.
when i use JSON.stringify
, $_POST
is not empty but it does not get sent as proper key value pairs on the request. i get the below
Array
(
[{"id":"21","content":"<p>html text</p>"}
)
so in the server side i have to do $_POST = json_decode(file_get_contents('php://input'), true);
how can i fix this so i dont have to do $_POST = json_decode(file_get_contents('php://input'), true);