【发布时间】:2011-07-31 08:48:47
【问题描述】:
我不知道如何将一堆 MySQL 行放入 JSON 数据结构并在 java 脚本中迭代每个行字段。
这是我在 codeigniter 中的查询
function get_search_results() {
//$this->db->like('title', $searchText);
//$this->db->orderby('title');
$query = $this->db->get('movies');
if($query->num_rows() > 0) {
foreach($query->result() as $movie) {
$movies[] = $movie->title;
}
}
return $movies;
}
为 json 编码数组
$rows= $this->movie_model->get_search_results();
echo json_encode($rows);
我的 jQuery AJAX 请求,
$.ajax({
type: "GET",
url: "publishlinks/search_movies",
data: searchString,
...
这就是我一直在尝试遍历 java 脚本中的行的方式。它遍历每个字符: 1 t 2 h 3 e 4 g ... 7 e 我需要这个:1比赛2输了3你
success:
function(result) {
$.each(result, function(key, val) {
alert(key + ' ' + val);
})
//alert(result);
}
【问题讨论】:
-
对我来说很合适。你遇到什么样的问题?有什么错误吗?
标签: php javascript jquery