我即将使用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”
答案 0 :(得分:0)
正如兰迪爵士所说。只需简单地加一个美元符号就可以解决问题。
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);
}
});
}