我对 Slim 框架和 PUT 请求有疑问。我有一个小的 jQuery 脚本,它会在单击按钮时更新到期时间。
$("#expiry-button").click(function(event) {
event.preventDefault();
$.ajax({
url: 'http://www.domain.com/expiry/38/',
dataType: 'json',
type: 'PUT',
contentType: 'application/json',
data: {aid:'38'},
success: function(){
var text = "Time updated";
$('#expiry').text(text).addClass("ok");
},
error: function(data) {
var text = "Something went wrong!";
$('#expiry').text(text).addClass("error");
}
});
});
我总是得到“出了点问题!”
在我配置 Slim 的 index.php 中,我有这个
$app->put('/expiry/:aid/', function($aid) use($app, $adverts) {
$id = $app->request()->put($aid);
$adverts->expand_ad_time($id["aid"]);
});
如果var_dump($id)
我得到 NULL
响应标头如下所示:
Status Code: 200
Pragma: no-cache
Date: Wed, 08 May 2013 12:04:16 GMT
Content-Encoding: gzip
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze15
Vary: Accept-Encoding
Content-Type: text/html; charset=utf-8
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Transfer-Encoding: chunked
Connection: Keep-Alive
Keep-Alive: timeout=15, max=100
Expires: Thu, 19 Nov 1981 08:52:00 GMT
和请求正文
Request Url: http://www.domain.com/expiry/38/
Request Method: PUT
Status Code: 200
Params: {
"aid": "38"
}
所以沟通是存在的,但不是预期的结果。我究竟做错了什么?