以下是我写的代码,通过ajax去请求是能返回图片的路径的,但是就没办法初始化,哪位高手帮帮忙????谢谢!!!
<script type="text/javascript">
// 初始化获取原有文件
$(function(){
$.ajax({
type:"post",
url:"{:U('map/getData')}",
data:{id:$("#id").val()},
dataType : "json",
success : function(data) {
var data1=eval(data);
showPhotos("img_url1",data1.map);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus);
}
});
});
function showPhotos(ctrlName,pic){
var ctrl=$("#"+ctrlName);
ctrl.fileinput({
language: 'zh',
uploadUrl: "{:U('map/upload')}", //上传后台操作的方法
uploadAsync: true, //设置上传同步异步 此为同步
maxFileSize: 800,
initialPreview: [ //预览图片的设置
"<img src='"+pic+"' class='file-preview-image' alt='肖像图片' title='肖像图片'>",
],
allowedFileExtensions: ['jpg','png'] //限制上传文件后缀
}).on('fileuploaded', function(event, data, previewId, index){
//alert(data);
var form = data.form, files = data.files, extra = data.extra,
response = data.response, reader = data.reader;
//alert(data.filenames);
var str = JSON.stringify(data);
alert(str);
//document.write(str);
alert(data.response.filename);
$("#mapImg").val(data.response.filename);
});
}
//showPhotos("./data/upload/map/1471835413_554564442.jpg");
</script>
先把排版搞好了先...