2016-09-07 7 views
0

を更新しても、MySQL内でAjaxを使用して更新するレコードを取得できません。レコードはVARCHAR(1000)です。構文エラーがある必要があります。しかし、私はそれを見ることはできません。私はすべてを試しました - どんなアイデアですか?ありがとう!Ajax Postを使用してMySQL Laravel 5.1をアップデートする理由何らかの理由で

$(".edit_comment").change(function(){ 

    var comment = $(".edit_comment").val() // This is just text from a text box. 
    var $id = $("#customer_id").val(); 
    $.ajax({ 
     headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, 
     type: "POST", 
     url: 'update_comment/'+$id, 
     data: comment, 
     success: function() { 
      console.log(comment, $id); // I can see the correct text & id here 
      alert('Your Comment is Updated') 
     }, 
     error: function() { 
      alert('there has been a system level error - please contact support') 
     } 
    }); 

Laravelコントローラー:

public function update_comment(Request $request, $id){ 

    $comment = $request->get('edit_comment'); 
    Quotation::where('id', $id) 
     ->update(['comment' =>$comment]); 
    } 

答えて

1

私はデータが

data: {edit_comment: comment} 

もないとされるべきだと思う、PHPの終了後にデータを取得するnowayがあります。

$comment = $request->get('edit_comment'); 
+0

血まみれの地獄、それは動作します!ありがとうございました !!しかし、あなたに正直なところ、この構文がなぜ機能するのか分かりません。説明できますか? tks! – Vince

+0

@Vince送信するフォームを作成するときと同じことですが、 ''のように 'name'と' value'の両方が必要です。それを理解する必要があります。 – Yarco

関連する問題