gpt4 book ai didi

javascript - 从 laravel Controller 将值传递给 ajax 然后获取特定字段

转载 作者:行者123 更新时间:2023-12-02 21:54:38 26 4
gpt4 key购买 nike

我如何获取 ID 或名称字段,然后将其附加到文本框,如果我以错误的方式处理此问题,请纠正我。

$(document).ready(function(){
var students = {!! json_encode($students->toArray()) !!};

//This Part Im Trying to get.
var name=$(students).val(name);
var id=$(students).val(id);

console.log(name);

});

Controller :

 $students=Student::all()->take(5);
return view('Examples.levels',compact('students'));

下图是我使用 console.log(students) 的结果 enter image description here

更新版本

$(document).ready(function(){
var students = {!! json_encode($students->toArray()) !!};
students.forEach(function(student) {
$('.content').append(
`<input name="name[]" value=`+student.name+`>`
);
console.log(student.name)
});
});

附加图像结果: enter image description here

最佳答案

试试这个。它将附加值。

students.forEach(function(student) {
$('.content').append(
`<input name="name[]" value="`+student.name+`">`
);
});

关于javascript - 从 laravel Controller 将值传递给 ajax 然后获取特定字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60035302/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com