我想在我的API使用http.put更新一些數據,但我總是得到「404未找到」。這裏是我的代碼:http.put:「404找不到」在離子2
TS文件:
activate(customer) {
if(this.mycode==this.cuscode) {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
let body = JSON.stringify(customer);
this.http.put('http://myApi.com/customer/' + this.id, body, options)
.map(res => res.json())
.subscribe(data => {
console.log("Successfully Activated your Account.");
}, (err) => {
console.log("ERROR: " +err);
});
}else {
this.wrongcode = true;
console.log("NOT ACTIVATED! Incorrect code mate.");
}
}
HTML文件:
<ion-item [(ngModel)]="mycode">
<ion-input type="text" placeholder="Activation Code" required></ion-input>
</ion-item>
<button ion-button (click)="activate(customer)"><ion-icon name="check"></ion-icon>Activate Now</button>
我得到這個錯誤:
PUT http://myApi/customer/72 404 (Not Found)
我的API是工作很好,但我不知道爲什麼它不是UND?希望你們能幫助我。先謝謝你。
可以從服務器,如果檢查你的api方法「放」而不是「get」。也可以嘗試從預先休息客戶端或任何其他休息客戶端打這個。 –
感謝您的回覆,但您的意思是從服務器檢查? – Patrick
嘗試在devtools中使用網絡標籤,通過console.log查看您的this.mycode和this.cucode –