如果你发现这个问题是错的,很抱歉。在我的网站中,我有两个div,一个div包含用户选择的图像,我已经通过Jquery预览了它。然后在控制器中获取这个图像并应用Codeigniter的翻转操作,现在我的问题是如何在不刷新整个页面的情况下用翻转的图像(将来自控制器)加载第二个div?I have three div's, how to load data in only a particular div without reloading the complete page in php-codeigniter?
我知道这个链接,但这里的数据来自数据库,而不是我的情况。那么如何在不加载整个页面的情况下调用特定div中的数据?因为我必须从控制器上传图像,所以这是我的控制器代码:
$filedata = $this->upload->data();
$data['img2'] = base_url().'/assets/images/'.$filedata['file_name'];
$this->load->view('pages/flipped',$data);
这是视图代码:
<div class="invert-grid-item invert">
<label>Upload Image</label>
<input type='file' name="userfile" size="20">
<img id="blah" src="#" alt="" />
</div>
<div class="invert-grid-item invert" id="result"></div>
<button id="uploaded_images" type="submit">Invert</button>
JS代码
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah')
.attr('src', e.target.result)
.width(200)
.height(200); };
reader.readAsDataURL(input.files[0]);
}
}
$('#files').on('click',function(){
var files = $('#files')[0].files;
$.ajax({
url:"<?php echo base_url(); ?>pages/flip",
method:"POST",
success:function(data)
{
$('#uploaded_images').html(data);
$('#result').val('');
}
})
});
</script>
发布于 2018-07-07 08:33:49
解决了我的问题,用JQuery做了一个ajax调用:
$(document).ready(function(){
$('#upload_form').on('submit', function(e){
e.preventDefault();
if($('#userfile').val() == '')
{
alert("Please Select the File");
}
else
{
$.ajax({
url:"<?php echo base_url(); ?>pages/flip",
method:"POST",
data:new FormData(this),
contentType: false,
cache: false,
processData:false,
success:function(data)
{
$('#result').html(data);
}
});
}
});
});
@ClaudiusDan和@saddam感谢你们的帮助!
发布于 2018-07-06 17:33:08
https://stackoverflow.com/questions/51207172
复制相似问题