我想知道如何使用http服務將參數從url傳遞到php。角4 - 如何使用參數從數據庫中獲取數據
服務:
getEmployeesById(data) {
let datas = JSON.stringify({'id':data});
return this.http.get('http://localhost/employees/?p=editEmployees', datas)
.map(response => response.json());
}
組分:
ngOnInit() {
this.activatedRoute.queryParams.subscribe((queryParams: Params) => {
let userId = queryParams['id'];
this.employeesServices.getEmployeesById(userId)
.subscribe(data => {
this.result = data
});
});
}
PHP:http://localhost/employees/?p=editEmployees
$editEmployees = mysqli_query($con, "SELECT * FROM $employeesTable WHERE emp_id = '".$_GET['id']."' ");
$rows = mysqli_fetch_assoc($editEmployees);
$emp[] = $rows;
echo json_encode($emp);
- 我創建了一個mysqli查詢來獲取員工ID。 - 然後在組件,我拿來從URL參數(ID)的EMP ID這樣
this.employeesServices.getEmployeesById(userId);
我的問題是,我不知道如果我傳遞的數據是正確的。
我使用
{{ result.first_name }}
顯示HTML數據,但我不能得到它的權利。
追加其他參數做你的控制檯錯誤,做一個帖子後到達您的服務器 –
嘗試數據:有一個問題'{{導致.first_name}?}'標記。 – DeborahK
我總是得到這個錯誤(core.es5.js:1020錯誤SyntaxError:意外的標記<位於JSON在位置0)我不知道如何正確讀取在PHP中的通過數據。並將其傳回組件並將其顯示爲HTML – edizonv