mercredi 7 septembre 2016

Updating MySQL Laravel 5.1 using Ajax Post

for some reason, I can not get a record within MySQL to update using Ajax. The record is a VARCHAR(1000). There has to be a syntax error. But I can not see it. I have tried everything - any ideas ? Thanks !

$(".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 Controller:

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

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire