1
我把這個數據 {ID = 「1」,標題= 「富」,imagedescription = 「酒吧」}如何使用PHP rest api獲取數據?
這是我的PHP端點
<?php
// This will update a photo that has been edited
if (isset($_GET['id'], $_GET['title'], $_GET['imagedescription']))
{
$id= $_GET['id'];
$title= trim($_GET['title']);
$imagedescription=trim($_GET['imagedescription']);
require 'db_connect.php';
$update_query = "Update images Set title = {$title}, imagedescription = {$imagedescription} Where id={$id}";
if($update = $db->query($update_query))
{
$response["success"] = 1;
$response["message"] = "Photo successfully updated.";
// echoing JSON response
echo json_encode($response);
}
else
{
$response["failed"] = 0;
$response["message"] = "Oops! An error occurred.";
$response["sql"] = $update_query;
// echoing JSON response
echo json_encode($response);
}
}
else
{
// required field is missing
$response["failed"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
我只是得到{ 「失敗」 :0,「郵件」:「缺少必填字段」},在郵遞員中有200個成功響應。
如何使用PHP從請求中獲取數據?
這是角服務
(function() {
angular.module('app')
.service('PhotosManager', ['$http', function($http) {
this.getPhotos = function() {
return $http.get("get_all_photos.php");
};
this.updatePhoto = function (id, data) {
return $http.put("update_photo.php"+ id, data);
};
}]);
})();
我可以看到一個成功的響應 請求方法:PUT 狀態代碼:200 OK
的可能的複製[如何訪問在服務器端PHP REST API將數據?](http://stackoverflow.com/questions/6805570/how-do-i-access-php-rest- api-put-data-on-the-server-side) –
你正在把這個數據放在這裏{{id =「1」,title =「foo」,imagedescription =「bar」}'。但從Ajax或從其他客戶端,它是GET還是POST? –
$ http.put(「update_photo.php」+ id,data); – ChibaKun