//this is my mysql result
$search_result=$this->Connect_user_model->get_user($key_word);
$info=array();
foreach($search_result as $row){
$info[]=array('username' => $row->username,
'email' => $row->email,
'gender' => $row->gender);
echo json_encode($info);'
}
我怎样才能循环这个响应?我得到了这样的回应——
0: {
username: iamanam,
email: 1,
gender: Male
}
email: "1"
gender: "Male"
username: "iamanam"
1: {
username: admin,
email: iamanam3@gmail.com,
gender: Male
}
email: "iamanam3@gmail.com"
gender: "Male"
username: "admin"
2: {
username: iamanam,
email: 1@1.com,
gender: Male
}
email: "1@1.com"
gender: "Male"
username: "iamanam"
当我在循环外回显 json_encode 时。它可以工作,但我得到每个结果双倍我使用这个函数进行循环----
function process_response(data){
var show_user='';
$.each(data,function(contact,contactInfo) {
show_user+='<div class="discounted-item '+contactInfo.gender+' music-playlist">';
show_user+='<img src="" alt="" class="music-playlist-left" width="38px" height="38px" />';
show_user+='<h1>';
show_user+=contactInfo.username;
show_user+='</h1>';
show_user+='<p>';
show_user+= contactInfo.gender;
show_user+='</p>';
show_user+='<a href="" title="" class="tips" rel="">';
show_user+='<img src="" alt="f" class="music-playlist-right" id="img"></a>';
show_user+='</div>';
}); // end of each()
// add finished HTML to page
$('#info').append(show_user);
}//process_responce