【发布时间】:2019-09-21 09:09:50
【问题描述】:
class LeavesController extends Controller
{
public function pullCon()
{
return json_encode(Leaves::all());
}
}
this is my route
Route::get('/folder/leaves', 'LeavesController@pullMetod');
and this is my json why wont it work
$(document).ready(function(){
$.ajax({
url:"/folder/leaves",
type: "get",
success: function(resuLt)
{
consoLe.log(result);
let obj = JSON.parse(result);
consoLe.log(obj);
$("table").append(<tr> <td>ID</td> <td>Name</td> <td>Mass</td>
<td>Year</td> </tr>);
for( let i=0; i<obj.lenght; i++)
{
$("table").append('<tr>');
$("table").append('<td>' + obj[i].id + '</td>');
$("table").append('<td>' + obj[i].earth_mass + '</td>');
$("table").append('<td>' + obj[i].year_lenght + '</td>');
$("table").append('</tr>');
}
}
});
});
它需要学说/dbal 作为依赖项。但是一些迁移功能已经需要 DBAL 才能工作。确保您填写 table_catalog (我猜它等同于数据库)。您可能需要稍微调整一下结果。
【问题讨论】:
-
在 ajax({}}) 你使用 dataType:'json',