Laravel 从 curl 得到 api 而不是用 ajax 得到 jsondecode
Laravel get api from curl than jsondecode with ajax
我有一条索引路线http://localhost/index
我需要帮助来创建 jquery ajax 以从 url http://localhost/mylist 获取 json 数据并将 json 数据格式化以将其显示为 html table.
这是我在 Laravel
中的 2 条路线
Route::get('index', function () {
return view('index');
});
Route::get('mylists', 'ExampleController@mylists');
这里是ExampleController.php方法
public function mylists()
{
\Here i do a cURL get request to my remote api befor I return $data
return $data = json_decode($contact_list)
}
所以如果有人导航到 url http://localhost/mylist 他们会看到
{ "name":"John", "age":30, "city":"New York"}
我也有一条索引路线http://localhost/index
我需要帮助来创建 jquery ajax 以从 url http://localhost/mylist 获取 json 数据并将 json 数据格式化以将其显示为 html table.
将数据传递给控制器查看
public function mylists()
{
$data['mylist'] = json_decode($contact_list);
return view('myview',$data);
}
创建视图文件 myview.blade.php 以 html 格式呈现数据
<table class="table table-striped">
<tr>
<th> Name</th>
<th> Age</th>
<th> City</th>
</tr>
@foreach($mylist as $list)
<tr>
<td>{{ $list->name}}</td>
<td>{{ $list->age}}</td>
<td>{{ $list->city}}</td>
</tr>
@endforeach
</table>
我有一条索引路线http://localhost/index 我需要帮助来创建 jquery ajax 以从 url http://localhost/mylist 获取 json 数据并将 json 数据格式化以将其显示为 html table.
这是我在 Laravel
中的 2 条路线 Route::get('index', function () {
return view('index');
});
Route::get('mylists', 'ExampleController@mylists');
这里是ExampleController.php方法
public function mylists()
{
\Here i do a cURL get request to my remote api befor I return $data
return $data = json_decode($contact_list)
}
所以如果有人导航到 url http://localhost/mylist 他们会看到
{ "name":"John", "age":30, "city":"New York"}
我也有一条索引路线http://localhost/index 我需要帮助来创建 jquery ajax 以从 url http://localhost/mylist 获取 json 数据并将 json 数据格式化以将其显示为 html table.
将数据传递给控制器查看
public function mylists()
{
$data['mylist'] = json_decode($contact_list);
return view('myview',$data);
}
创建视图文件 myview.blade.php 以 html 格式呈现数据
<table class="table table-striped">
<tr>
<th> Name</th>
<th> Age</th>
<th> City</th>
</tr>
@foreach($mylist as $list)
<tr>
<td>{{ $list->name}}</td>
<td>{{ $list->age}}</td>
<td>{{ $list->city}}</td>
</tr>
@endforeach
</table>