2
我有一個調用REST修身服務骨幹腳本。 GET請求正常工作,PUT請求返回404 Not Found。注:這是工作,直到我的代碼是最近移動到另一臺服務器(和它的作品在本地),所以我猜它是與Apache的配置設置。這裏的骨幹腳本的一個片段:PUT請求導致404未找到
jQuery(document).ready(function ($) {
//define box model
var Box = Backbone.Model.extend({
url: function() {
var urlId = (this.id) ? this.id : "";
var myUrl = "/wp-includes/api/service.php/box/" + urlId;
return myUrl;
}
});
var BoxView = Backbone.View.extend({
tagName: "div",
template: $("#boxTemplate").html(),
initialize: function() {
this.model = new Box(box);
this.render();
},
saveBox: function(e){
e.preventDefault();
$("#boxMessage").empty();
var formData = {},
prev = this.model.previousAttributes();
$(e.target).closest("form").find(":input").not("button").each(function(){
var el = $(this);
formData[el.attr("id")] = el.val();
});
this.model.set(formData);
this.model.save(
{ },
{
success: function() {
$("#boxMessage").html("Box information saved.");
},
error: function() {
}
}
);
}
這裏的修身REST服務的一個片段:
<?php
require 'Slim/Slim.php';
$app = new Slim();
$app->get('/workouts/:id', 'getWorkout');
$app->put('/box/:id', 'updateEventBox');
$app->run();
function getWorkout($id) {
echo json_encode(GetEventCompetitorWorkout($id));
}
function updateEventBox($id) {
$request = Slim::getInstance()->request();
$body = $request->getBody();
$eventBox = new EventBox(null);
$eventBox->TakeJson($body);
$eventBox->Save();
}
,這裏是該請求的頭信息:
Request URL:http://www.mydomain.com/wp-includes/api/service.php/box/1
Request Method:PUT
Status Code:404 Not Found
更新:剛剛測試了一個POST到相同的服務,它工作正常。 PUT仍然失敗。