0
我创建了一个控制器&视图如下 - 我试图通过jSON对象循环 - 任何人都可以协助?循环通过这个json对象(jquery)与Codeigniter
任何人都可以演示如何循环浏览视图中的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);
});
});
可能重复:http://stackoverflow.com/questions/2342371/jquery-loop-on-json-data-using-each – Techie