-1
這是我第一次試圖檢索使用AJAX/JSON格式的圖像,所有其他變量顯示除了圖像,因爲我不知道如何將語法集成在AJAX, 當我打開瀏覽器上的檢查元素的圖像名稱正在顯示,並將其保存到圖像文件夾以及正確 我只需要你們幫助我在沒有功能的窗體裏面顯示圖像 Thanks in推進什麼檢索圖像從數據庫使用JSON AJAX函數codeigniter
這是我的AJAX功能
//Ajax Load data from ajax
$.ajax({
url : "<?php echo site_url('person/ajax_edit/')?>/" + firstname,
type: "GET",
dataType: "JSON",
success: function(data)
{
$('[name="id"]').val(data.id);
$('[name="firstName"]').val(data.firstname);
$('[name="lastName"]').val(data.lastname);
$('[name="gender"]').val(data.gender);
$('[name="address"]').val(data.address);
\t \t \t $('[name="gender"]').val(data.gender);
\t \t \t $('[name="telephone"]').val(data.telephone);
\t \t \t $('[name="level"]').val(data.level);
\t \t \t $('name="image"').val(data.image)
\t \t \t $('[name="religion"]').val(data.religion);
\t \t \t $('[name="entrance"]').val(data.entrance);
\t \t \t $('[name="graduate"]').val(data.graduate);
\t \t \t $('[name="parents"]').val(data.parents);
$('[name="dob"]').datepicker('update',data.dob);
$('#modal_form').modal('show'); // show bootstrap modal when complete loaded
$('.modal-title').text('Edit Person'); // Set title to Bootstrap modal title
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error get data from ajax');
}
});
這是控制器
public function ajax_edit($firstname)
\t {
\t \t $data = $this->person->get_by_id($firstname);
\t \t $data->dob = ($data->dob == '0000-00-00') ? '' : $data->dob; // if 0000-00-00 set tu empty for datepicker compatibility
\t \t
\t \t echo json_encode($data);
\t }
這是我的模型
public function get_by_id($firstname)
\t {
\t \t /*
\t \t $this->db->from($this->table);
\t \t $this->db->where('id',$id);
\t \t $query = $this->db->get();
\t \t return $query->row();
\t \t */
\t \t
\t \t
\t \t $this->db->select("e.*,edu.*");
\t \t $this->db->from("student_details e");
\t \t $this->db->join("images edu", "edu.firstname = e.firstname", 'left');
\t \t $this->db->where('e.firstname', $firstname);
\t \t $result = $this->db->get();
\t \t return $result->row();
\t \t
\t }
這是我的看法
<div class="form-group">
<label class="control-label col-md-3">Religion</label>
<div class="col-md-9">
<select name="religion" class="form-control">
<option value="">--Select Religion--</option>
<option value="Christain">Christain</option>
<option value="Muslim">Muslim</option>
</select>
<span class="help-block"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-4">Image</label>
<div class="">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 200px; height: 150px;"><img src="assets/img/demoUpload.jpg" alt="" /></div>
<div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 200px; max-height: 150px; line-height: 20px;"></div>
<div align="center">
<span class="btn btn-file btn-primary"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" name="userfile" ></span>
<a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload">Remove</a>
<span class="help-block"></span>
</div>
</div>
</div>
</div>
什麼是數據庫中的圖像字段的數據類型? – Junaid
你的圖像選擇器在'$('name =「image」').val(data.image)'中是不正確的。 –
數據庫中的數據字段是圖像和文件名是userfile不是圖像...我犯了一個Ajax函數內部錯誤nd我已經糾正它仍然不工作.. – user3655211