无法识别数据变量。未捕获的引用错误: 未定义edu_id



我将使用Laravel 将edu_id从ajax传递到我的控制器

锚点标签

<a href="javascript:void(0);" onclick="showEditEducation(some_specific_id);" title=""><i class="la la-pencil"></i></a>

Javascript函数

function showEditEducation($edu_id)
{
console.log($edu_id);
$.ajax({
type: "POST",
url: "{{ route('show-edit-education', $user->id) }}",
data: {"education_id": edu_id,"_token": "{{ csrf_token() }}"},
datatype: 'json',
success: function (json) {
$("#showMe").html(json.html);
}
});
}

Laravel控制器

public function showEditEducationForm(Request $request, $user_id)
{
$user = User::find($user_id);
$education_id = $request->input('education_id'); 
$applicantEducation = ApplicantEducation::find($education_id);
dd($applicantEducation);
}

console.log输出正常。它返回一个数字。唯一的问题是ajax无法识别"edu_id">

正如Randy爵士所说。只要简单地打一个美元符号就能解决问题。
edu_id

$edu_id

最终javascript函数代码

function showEditEducation($edu_id)
{
console.log($edu_id);
$.ajax({
type: "POST",
url: "{{ route('show-edit-education', $user->id) }}",
data: {"education_id": $edu_id,"_token": "{{ csrf_token() }}"},
datatype: 'json',
success: function (json) {
$("#showMe").html(json.html);
}
});

}

最新更新