我已经创建了一个控制器和视图,如下所示 - 我正在尝试遍历 JSON 对象 - 任何人都可以提供帮助吗?
谁能演示如何在视图中循环遍历 json 对象?
//Controller PHP function:
public function ajax_get_all()
{
$stockists = $this->stockists_model->get_all();
header('Content-type: application/json');
echo json_encode($stockists);
}
//HTML View
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
// Stuff to do as soon as the DOM is ready;
$.getJSON("/stockists/ajax_get_all", function(data) {
var obj = jQuery.parseJSON(data);
//console.log(obj);
});
});