0
JavaScript代碼如何讀取在PHP服務器端對象值
function addSupplier(supplier) {
alert(supplier.name);
alert(supplier.mobile);
var deferred = $q.defer();
$http.post(REST_SERVICE_URI, supplier)
.then(
function (response) {
deferred.resolve(response.data);
},
function(errResponse){
console.error('Error while creating Supplier');
deferred.reject(errResponse);
}
);
return deferred.promise;
}
PHP代碼
/*Create New Supplier*/
$app->post('/suppliers', function() use ($app) {
// check for required params
//verifyRequiredParams(array('name', 'mobile'));
$response = array();
$name = $app->request->post($supplier->name);
$mobile = $app->request->post($supplier->mobile);
$db = new DbHandler();
$supplier_id = $db->createSupplier($name, $mobile);
if ($supplier_id != NULL) {
$response["error"] = false;
$response["message"] = "Supplier created successfully";
$response["supplier_id"] = $supplier_id;
} else {
$response["error"] = true;
$response["message"] = "Failed to create supplier. Please try again";
}
echoRespnse(201, $response);
});
我想讀的PHP supplier.name和supplier.mobile。上面的代碼不起作用。
'$ app-> request-> post('name')'和'$ app-> request-> post('mobile')'也許? – bishop