我已成功发送数据,但在网络标签中,PUT请求为我提供了 500内部服务器错误。我使用laravel作为我的服务器端框架,在我的控制器内部我更新了这样的数据。
public function update($id)
{
$input = Input::all();
$player = Player::find($id);
$player->playerName = $input['playerName'];
$player->teamID = $input['teamID'];
$player->points = $input['points'];
$player->made_one = $input['made_one'];
$player->made_two = $input['made_two'];
$player->made_three= $input['made_three'];
$player->missed_one = $input['missed_one'];
$player->missed_two = $input['missed_two'];
$player->missed_three =$input['missed_three'];
$player->percentage = $input['percentage'];
$player->assists =$input['assists'];
$player->rebounds = ['rebounds'];
$player->steals = $input['steals'];
$player->turnovers = $input['turnovers'];
$player->fouls = $input['fouls'];
$player->feed = $input['feed'];
$player->save();
}
这对于backbone.js非常有用,这是我的javascript框架,我在更新模型时调用.save()
方法,上面的$input
属性是我模型中的属性。< / p>
奇怪的是,如果我更新少$input
个属性并设置如下代码,那么我就不会得到500错误。
public function update($id)
{
$input = Input::all();
$player = Player::find($id);
$player->playerName = $input['playerName'];
$player->teamID = $input['teamID'];
$player->points = $input['points'];
$player->save();
}
这两个函数仍然使用正确的数据更新我的数据库表。
这是500错误消息
{
"error":{
"type":"ErrorException",
"message":"preg_replace(): Parameter mismatch, pattern is a string while replacement is an array",
"file":"C:\\wamp\\www\\basketball-app-framework\\vendor\\laravel\\framework\\src\\Illuminate\\Support\\helpers.php",
"line":900
}
}
以下是我使用backbone.js
保存它的方法var addThis = parseInt(this.model.get('assists')) + 1;
this.model.save({assists: addThis});
这是我保存点数的方法,我添加到made_one
属性,同时还添加到points
属性。
var addMake = parseInt(this.model.get('made_one')) + 1;
var addOne = parseInt(this.model.get('points')) + 1;
this.model.save({made_one: addMake, points: addOne});
答案 0 :(得分:2)
这应该有效:
$player->rebounds = ['rebounds'];
至$player->rebounds = $input['rebounds'];