[英]jQuery File Upload (Blue imp) Symfony 2 405 method not allowed
[英]405 Method Not Allowed in Symfony 3
我有這條路線的路線
/**
* @Method({"DELETE"})
* @Route("/secure/users")
*/
當我嘗試做一個cUrl
<html> <head> <meta charset="UTF-8" /> <title>An Error Occurred: Method Not Allowed</title> </head> <body> <h1>Oops! An Error Occurred</h1> <h2>The server returned a "405 Method Not Allowed".</h2> <div> Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused. </div> </body> </html>
我也嘗試啟用
Request::enableHttpMethodParameterOverride();
在app.dev和app_dev.php中,我可以處理PUT
請求。
將此參數添加到curl請求:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
或者在命令行中
curl -X DELETE "http://localhost/secure/users"
如果您正在使用jQuery執行XHR請求,那就行了
$.ajax({
url: '/secure/users',
type: 'DELETE',
data: { id: resourceToDelete }
success: function(result) {
// Do something with the result
}
});
對於純javascript:
var req = new XMLHttpRequest();
req.open('DELETE', '/secure/users');
req.setRequestHeader("Content-type", "application/json");
req.send({ id: 'entityIdentifier' });
如果你想通過瀏覽器訪問它或傳遞查詢參數如/secure/users?id=x
,請使用GET:
/**
* @Method({"GET"})
* @Route("/secure/users")
*/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.