我想在我的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 –