2017-09-27 99 views
0

我收到此錯誤:XMLHttpRequest無法加載http://api.azharcouncil.com/api/Employees/DeleteEmployee?id=11。試圖從表格中刪除員工時,預檢的響應具有無效的HTTP狀態代碼405。預檢的響應具有無效的HTTP狀態代碼405角度4

數據storage.service.ts:

deleteEmployee(employeeId: any){ 
    let url = 'http://api.azharcouncil.com/api/Employees/DeleteEmployee?id='+employeeId; 
let headers = new Headers(); 
headers.append('Content-Type', 'applications/json') 
let options = new RequestOptions({ headers: headers }); 
return this.http.delete(url, options) 
.map(resp => resp.json()); 

    } 

employees.component.ts:

onDelete(employeeId: any){ 

    this.dataStorageService.deleteEmployee(employeeId).subscribe(
    data => { 
     console.log(data); 
     return true; 
     }, 
     error => { 
      console.log(error.json().error); 
      console.error("Error delete employes!"); 
      return false; 
     } 
     ); 
    console.log(employeeId); 
    } 

**當我在郵遞員嘗試這個網址我可以刪除員工**

回答

0

我認爲請求的內容類型應該是應用程序/ json也更改標題應附加鍵添加標題選項

deleteEmployee(employeeId: any){ 
let url = 'http://api.azharcouncil.com/api/Employees/DeleteEmployee?id='+employeeId; 
let headers = new Headers(); 
headers.append('Content-Type', 'application/json') 
return this.http.delete(url,{ headers: headers }) 
       .map(resp => resp.json()) 
       .catch(this.handleError); 


} 
+0

headers.append需要2個參數把它給我的錯誤 –

+0

刪除「{}」是錯字錯誤對不起我錯 – Robert

+0

同樣的錯誤發生 –

相關問題