0

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]);
     }

1 Answer 1

1

i think the data should be

data: {edit_comment: comment}

Or else, there's noway to get the data at php end.

$comment = $request->get('edit_comment');
Sign up to request clarification or add additional context in comments.

2 Comments

Bloody Hell, it works ! Thank You !! But to be honest with you, I don't understand why this syntax works. Can you explain? tks !
@Vince that is same thing when you create form to do submitting, you need both name & value as in <input name="edit_comment" value="..." >, so of cause, you should figure out it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.