unemployment Posted November 27, 2012 Share Posted November 27, 2012 (edited) I am sending a DELETE request in backbone using: this.model = new domain.city.delete_photo.Model(); this.model.url = "/assets/ajax/delete_image.php?img_id="+id; this.model.id = id; this.model.destroy({ "success" : this.success, "error" : this.error }); And that sends a DELETE request to the server with the URL something like: http://localhost/ass...ge.php?img_id=9 The problem is, I can't seem to access the img_id. In my ajax file I have: $_DELETE = array(); if($_SERVER['REQUEST_METHOD'] == 'DELETE') { parse_str(file_get_contents('php://input'), $_DELETE); } print_array($_DELETE); Why doesn't this work? The array returns empty! Edited November 27, 2012 by unemployment Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/ Share on other sites More sharing options...
mrMarcus Posted November 27, 2012 Share Posted November 27, 2012 (edited) "DELETE" is not a valid 'REQUEST_METHOD'. Allowed REQUEST_METHOD's: 'GET', 'HEAD', 'POST', 'PUT'. Edited November 27, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395700 Share on other sites More sharing options...
unemployment Posted November 27, 2012 Author Share Posted November 27, 2012 "DELETE" is not a valid 'REQUEST_METHOD'. Allowed REQUEST_METHOD's: 'GET', 'HEAD', 'POST', 'PUT'. Is that really the case? My if($_SERVER['REQUEST_METHOD'] == 'DELETE') is met. Surely, there must be a way to use this. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395707 Share on other sites More sharing options...
requinix Posted November 27, 2012 Share Posted November 27, 2012 "DELETE" is not a valid 'REQUEST_METHOD'. Allowed REQUEST_METHOD's: 'GET', 'HEAD', 'POST', 'PUT'. It most certainly is valid. So are OPTIONS and TRACE and CONNECT. OP: Are you sure $_GET is empty? I'd expect it to have your img_id just fine. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395708 Share on other sites More sharing options...
mrMarcus Posted November 27, 2012 Share Posted November 27, 2012 Hmm... never come across that in the documentation. My bad. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395713 Share on other sites More sharing options...
unemployment Posted November 27, 2012 Author Share Posted November 27, 2012 It most certainly is valid. So are OPTIONS and TRACE and CONNECT. OP: Are you sure $_GET is empty? I'd expect it to have your img_id just fine. Why would I have to print $_GET? It's my $_DELETE that is empty. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395716 Share on other sites More sharing options...
requinix Posted November 27, 2012 Share Posted November 27, 2012 Because I'm pretty sure php://input will be empty. That's not where the data you want is. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395721 Share on other sites More sharing options...
mrMarcus Posted November 27, 2012 Share Posted November 27, 2012 Is that really the case? My if($_SERVER['REQUEST_METHOD'] == 'DELETE') is met. Surely, there must be a way to use this. Have you verified it's being met? Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395722 Share on other sites More sharing options...
unemployment Posted November 28, 2012 Author Share Posted November 28, 2012 Have you verified it's being met? Yes, I have verified the condition is being met. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395768 Share on other sites More sharing options...
unemployment Posted November 28, 2012 Author Share Posted November 28, 2012 Because I'm pretty sure php://input will be empty. That's not where the data you want is. Correct, it is returning empty. Do you know how I get the data? The parameters are being passed in according to firebug. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395770 Share on other sites More sharing options...
requinix Posted November 28, 2012 Share Posted November 28, 2012 Are you sure $_GET is empty? I'd expect it to have your img_id just fine. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395774 Share on other sites More sharing options...
unemployment Posted November 28, 2012 Author Share Posted November 28, 2012 Wow.... GET does have the img_id. This makes no sense to me though. Can you explain why this happens? Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395778 Share on other sites More sharing options...
requinix Posted November 28, 2012 Share Posted November 28, 2012 Because you put it in the URL. $_GET is how to get to that data. Just because it's a DELETE doesn't mean that's handled differently. Quote Link to comment https://forums.phpfreaks.com/topic/271268-php-using-http-delete-and-backbone/#findComment-1395805 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.