Hi, I am trying to make a delete request using ajax method of jquery as follows
$.ajax(
{
type: 'DELETE',
url: '/tagz',
data: {id: taskId},
success: function(data)
{
console.log(data);
}
});
And when I see the console in chrome, I find in the request headers that a GET request is made instead of DELETE. and in firefox console I see the following.
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]
On server side I am simply maintaining the following code.
$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;
}
I don't see the request getting into the case 'DELETE'
. It's getting into the case 'GET'
instead.
Following is the .htaccess file that I am using at the server for the purpose of clean urls.
RewriteEngine on
RewriteRule ^(.*)$ index.php [L,QSA]
Please help me in making DELETE requests. Thanks!