我一直試圖從角度發佈數據到php整天,但我感覺相當卡住。 這是角度控制我的方法:角度post方法到php
function submit() {
var JSONObject = {
"name":$rootScope.name,
"surname":$rootScope.surname,
"email":$rootScope.email,
"review":$rootScope.review
};
debugger;
var Results = UniversalService.PostReview(JSONObject);
}
然後它去UniversalService在我的$ http.post方法是:
function PostReview(JSONObject) {
debugger;
$http.post('http://localhost:8000/creation', JSONObject).then();
debugger;
}
一切順利,直到當它發送數據到這一點PHP(我的網頁API服務是流明框架)
在我DatabaseController.php我希望收到我的JSON對象(我很初學者,所以我希望這就是我失敗)
public function created(Request $request)
{
$inputJSON = file_get_contents('php://input');
$input= json_decode($inputJSON, TRUE); //convert JSON into array
print_r(json_encode($input));
/* $user=[
'name'=>$request->input('name'),
'surname'=>$request->input('surname'),
'email'=>$request->input('email'),
'review'=>$request->input('review'),
];
$time=$this->getTime();*/
// return DatabaseModel::newUser($user);
}
在routes.php文件
$app->post('/creation', [ 'as'=>'creation','uses'=> '[email protected]']);
我用GET和POST這裏走出的絕望,我似乎無法得到它的權利都沒有。也在routes.php我啓用標題('訪問控制,允許來源:*');而且我不確定我是否需要在角度上做到這一點(以及如何)。
但郵遞員似乎工作,我有附加功能還有,當我進入:http://localhost:8000/creation到郵遞員,我得到空從我在調用另一個函數的JSON對象和時間創建()
你'後'到'獲取'URL – aynber
我改變'get'到'後'routes.php,仍然有問題:( – user122222
顯示你的錯誤js和路線都有帖子。 – aynber