使用 Ajax Post 更新 MySQL Laravel 5.1
Updating MySQL Laravel 5.1 using Ajax Post
出于某种原因,我无法获取 MySQL 内的记录以使用 Ajax 进行更新。记录是 VARCHAR(1000)。必须有语法错误。但我看不到它。我已经尝试了一切 - 有什么想法吗?谢谢 !
$(".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]);
}
我觉得数据应该是
data: {edit_comment: comment}
否则无法获取php端的数据
$comment = $request->get('edit_comment');
出于某种原因,我无法获取 MySQL 内的记录以使用 Ajax 进行更新。记录是 VARCHAR(1000)。必须有语法错误。但我看不到它。我已经尝试了一切 - 有什么想法吗?谢谢 !
$(".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]);
}
我觉得数据应该是
data: {edit_comment: comment}
否则无法获取php端的数据
$comment = $request->get('edit_comment');