dongweihuan8610
2015-06-05 10:26
浏览 153
已采纳

在Laravel中使用ajax发布表单

I know this question has been out there many times, however I am unable to get through this.

Here is my route:

Route::post('/masters/board/edit', 'MastersController@editBoard');

My Controller:

public function editBoard() {
        $board = Board::findOrFail(Input::get('id'));
        $board->nick_name        = Input::get('nick_name');
        $board->board_name        = Input::get('board');
        $board->type                        = Input::get('type');
        $board->save();

        return Redirect::action('MastersController@getBoards');
    }

My JS:

$("#edit_form").submit(function(e) {
    e.preventDefault();

    var type = "#edit_form";

    var formData = {
          id : $(type + " #id").val(),
          nick_name : $(type + " #nick_name").val(),
          name : $(type + " #board").val()
      }

    $.ajax({
      type: "POST",
      url: "masters/board/edit",
      data: formData,
      success: function(data) {
        console.log(data);
      }
    });
  });
});

This is throwing an error:

[Error] Failed to load resource: the server responded with a status of 500 (Internal Server Error) (edit, line 0)

Can anyone see a reason why?

图片转代码服务由CSDN问答提供 功能建议

我知道这个问题已多次出现,但我无法解决这个问题。

这是我的路线:

  Route :: post('/ masters / board / edit','MastersController @ editBoard'); 
 <  / code>  
 
 

我的控制器:

  public function editBoard(){
 $ board = Board :: findOrFail(Input ::  get('id')); 
 $ board-&gt; nick_name = Input :: get('nick_name'); 
 $ board-&gt; board_name = Input :: get('board'); 
 $ board  - &gt; type = Input :: get('type'); 
 $ board-&gt; save(); 
 
返回Redirect :: action('MastersController @ getBoards'); 
} 
   
 
 

我的JS:

  $(“#edit_form”)。submit(function(e){
 e.preventDefault  (); 
 
 var type =“#edit_form”; 
 
 var formData = {
 id:$(type +“#id”)。val(),
 nick_name:$(type +“  #nick_name“)。val(),
 name:$(type +”#board“)。val()
  } 
 
 $ .ajax({
 type:“POST”,
 url:“masters / board / edit”,
 data:formData,
 success:function(data){
 console.log  (数据); 
} 
}); 
}); 
}); 
   
 
 

这是一个错误: \ n

  [Error]无法加载资源:服务器响应状态为500(内部服务器错误)(编辑,第0行)
   
 
  

任何人都可以看到原因吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题