我試圖使用jQuery的AJAX方法如下DELETE請求移動響應
$.ajax(
{
type: 'DELETE',
url: '/tagz',
data: {id: taskId},
success: function(data)
{
console.log(data);
}
});
做出刪除請求而當我在Chrome中看到控制檯,我發現在請求頭一個使用GET請求而不是DELETE。並在Firefox的控制檯中,我看到以下內容。
23:50:52:658: Network: DELETE http://test.goje87.com/tagz [HTTP/1.1 301 Moved Permanently 947ms]
23:50:53:614: Network: GET http://test.goje87.com/tagz/ [HTTP/1.1 200 OK 400ms]
在服務器端,我簡單地維護下面的代碼。
$reqMethod = $_SERVER['REQUEST_METHOD'];
switch($reqMethod)
{
case 'GET':
Utils::printR('Will provide the resource.');
selectObjects();
break;
case 'POST':
Utils::printR('Will create a new record.');
createObject();
break;
case 'PUT':
Utils::printR('Will update the record.');
break;
case 'DELETE':
Utils::printR('Will delete the record.');
Utils::output($_SERVER);
break;
}
我沒有看到請求進入case 'DELETE'
。它正在進入case 'GET'
。
以下是我在服務器上用於清理URL的.htaccess文件。
RewriteEngine on
RewriteRule ^(.*)$ index.php [L,QSA]
請幫我在做刪除請求。謝謝!
DELETE和PUT是有效的HTTP請求方法,請參見第9.6和9.7節:http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html – PatrikAkerstrand 2010-10-03 18:48:55
沒有刪除或放入jQuery.ajax( ) – 2010-10-03 18:51:25
夠公平的。似乎我不能刪除倒票,除非答案被編輯? – PatrikAkerstrand 2010-10-03 19:05:03