2017-07-30 82 views
0

這是我的.htaccess文件。無法從角度js執行PUT和DELETE應用程序

RewriteEngine On 

# Some hosts may require you to use the `RewriteBase` directive. 
# If you need to use the `RewriteBase` directive, it should be the 
# absolute physical path to the directory that contains this htaccess file. 
# 
# RewriteBase/

# Cross domain access 
Header add Access-Control-Allow-Origin "*" 
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type, authorization" 
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS" 
Header add Access-Control-Request-Origin "*" 
Header add Access-Control-Request-Headers "origin, x-requested-with, content-type, authorization" 
Header add Access-Control-Request-Methods "PUT, GET, POST, DELETE, OPTIONS" 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ index.php [QSA,L] 
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},last] 

但是,當我試圖執行PUT請求時,它給了我這樣的錯誤。

:63342/WEB-wokoshop伴侶/ index.html的_ijt = vgfnsnd7c4g6l47qh3kt00i8c8#/供應商:?!1周 的XMLHttpRequest無法加載http://abcd.com/SupplierApi/v1/supplier/5。預檢 響應具有無效的HTTP狀態碼404

這是怎麼了,從製作的角度

function updateSupplier(supplier, id) { 
    var data = { 
     name: supplier.name, 
     mobile: supplier.mobile 
    }; 

    var req = { 
     method : 'PUT', 
     url : REST_SERVICE_URI2 + '/' + supplier.id, 
     data : JSON.stringify(data), 
     headers : { 
      'Content-Type' : 'application/json' 
     } 
    }; 


    $http(req).then(
     function(response) { 
      alert('supplier updated.'); 
      console.log(data); 
     }, 
     function(data) { 
      consile.log(data); 
      alert('update supplier error.'); 
      alert(data.statusText); 

     }); 

} 

問題是什麼要求?我錯過了什麼?

+0

嘗試捕獲您的錯誤並通過添加'.catch((error)=> {console.log(error.response)}) –

回答

0

嘗試此刪除: - $ http.delete( 'URL /刪除',{PARAMS:{ 'ID':ID}}) 嘗試此更新: - $ http.put(「URL /更新',{params:{'Id':Id}})

相關問題