아래와 같이 jquery에서 응답을 받고 있습니다. ajax 요청을 통해 db의 이미지를 표시하고 싶습니다. 내 컨트롤러 코드 :
public function images($id='')
{
$this->load->model('gallery');
$data = this->gallery_model->getimages($this->input->post('id'));
echo json_encode($data);
}
내 아약스 :
function imageslide(folderid){
$.ajax({
url: "<?php echo site_url() ?>/welcome/images",
type: "POST",
dataType: "json",
data: {id: folderid},
success: function(result) {
if(result){
resultObj = eval (result);
alert(JSON.stringify(resultObj));
}else{
alert("error");
}
}
});
Network
탭 에서받은 결과 는
[{"id":"153","file_name":"DSC00081.JPG","created":"2017-05-23 09:36:32","modified":"2017-05-23 09:36:32","status":null,"folder_id":"50"},{"id":"154","file_name":"DSC00082.JPG","created":"2017-05-23 09:36:32","modified":"2017-05-23 09:36:32","status":null,"folder_id":"50"},{"id":"155","file_name":"DSC00083.JPG","created":"2017-05-23 09:36:32","modified":"2017-05-23 09:36:32","status":null,"folder_id":"50"}]
<img>
태그 의 브라우저에 이미지를 표시하는 방법을 모르겠습니다 . 보시다시피 jpeg
경고 창에 들어갑니다. 친절하게 도와주세요 .. 미리 감사드립니다!
예를 들어 배열의 첫 번째 인덱스와 함께 jQuery를 사용하여 이미지를 추가 할 수 있습니다.
$('#container').append('<img src="' + result[0].file_name + '" />');
각 이미지를 추가하려면 forEach 루프를 사용할 수 있습니다.
result.forEach(function (image) {
$('#container').append('<img src="' + image.file_name + '" />');
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다