RouteCollection.php第219行中的MethodNotAllowedHttpException:

时间:2016-05-04 05:43:51

标签: javascript php laravel-5

运行代码

时,我收到MethodNotAllowedHttpException

这是我的HTML代码

<form method="POST" action="" role="form">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
    <div class="panel panel-default ">
        <div class="container">
            <div class="panel-body">
                <div class="form-group">
                    <label for="firstName">First Name *</label>
                    <input name="fname" type="text" class="form-control" id="firstName" placeholder="Enter First Name" required>
                </div>
                <div class="form-group">
                    <label for="lastName">Last Name *</label>
                    <input name="lname" type="text" class="form-control" id="lastName" placeholder="Enter Last Name" required>
                </div>
                <div class="form-group">
                    <label for="qualification">Qualification *</label>
                    <input name="qualification" type="text" class="form-control" id="qualification" placeholder="BE, MCA, MBA Etc." required>
                </div>
                <div class="form-group">
                    <label for="emailAddress">Email address *</label>
                    <input name="email" type="email" class="form-control" id="emailAddress" placeholder="Enter Email" required>
                </div>
                <div class="form-group">
                    <label for="contactmessage">Message</label>            
                    <textarea name="desc" type="text" class="form-control" id="contactmessage" placeholder="Message" rows="2"></textarea>
                </div>
                <input type="submit" id="add" class="btn btn-primary" onclick="addUpdateData(id)" value="Add"></button>
            </div>
        </div>
    </div>
</form>

这是javascript函数

function addUpdateData(data)
{

if(data=="add")
{

  $(function(){
  $.ajax({
    method : "POST",
    url: "welcome/add",                
    data: {id: data},
    success : function(response)
    {
      alert(response);
      window.location.reload();

    });
  });

}
else
{
$(function(){
  $.ajax({
    method : "post",
    url: "welcome/update",        
    data: {id: data},        
    success : function(response)
    {
      alert(response);
      window.location.reload();
    }

  });


});
 } 
}

这是routes.php的代码

Route::post('welcome/add','FormController@addData');
Route::post('welcome/update','FormController@updateData');

这是Controller的代码 addData函数

public function addData()
{
    $bs = new Basicusers; //model from database
    $bs->fname = $req->fname;
    $bs->lname = $req->lname;
    $bs->qualification = $req->qualification;
    $bs->email = $req->email;
    $bs->desc = $req->desc;
    $bs->save();
    return back();
}

updateData函数

public function updateData($id, Request $req)
{
    $bs = new Basicusers; //model from database

    $bs->fname = $req->fname;
    $bs->lname = $req->lname;
    $bs->qualification = $req->qualification;
    $bs->email = $req->email;
    $bs->desc = $req->desc;

    $olddata = Basicusers::find($id); //finding data by ID

    $olddata.update($bs); //overwrite new data to specific ID
    return back();
}

0 个答案:

没有答案