vuejs2 - vuejs - sending post data to php -
i using due-resource send data php:
var data = {name: "abc", rank: "mid range"}; this.$http.post('../../static/php/savedata.php', {postdata: json.stringify(data)}) .then((response) => { console.log(response); }); then process , send data savedata.php test:
<?php $postdata = json_decode(file_get_contents('php://input'),true); $rank = $posteddata['rank']; $arr = array('status'=>'ok','rank'=>$rank); echo json_encode($arr); ?> i null rank. tried other ways in php:
$postdata = json_decode($post['postdate'],true); or
$postdata = $post['postdate']; all of them give me null. missing here?
i figured out wrong.
because data object, need to:
this.$http.post('../../static/php/savedata.php',json.stringify(data)) instead of:
this.$http.post('../../static/php/savedata.php',{postdata: json.stringify(data)})
Comments
Post a Comment