bootstrap fileinput initialization

WBOY
Release: 2016-08-25 10:37:32
Original
2045 people have browsed it

<code>      我想通过以下代码初始化fileinput,后台文件也有返回值,但是现在就没法初始化,哪位高手帮我看看,谢谢!
        <script type="text/javascript">
        
        // 初始化获取原有文件  
      $(function(){  
        $.ajax({  
           type:"post",  
           url:"{:U('map/getData')}",  
           data:{id:$("#id").val()},
           dataType : "json",  
           success : function(data) { 
           alert("success"); 
           var data1=eval(data);
           alert(data1.map);
           showPhotos(data1.map);  
           },  
           error: function(XMLHttpRequest, textStatus, errorThrown) {  
                  alert(XMLHttpRequest.status);  
                  alert(XMLHttpRequest.readyState);  
                  alert(textStatus);   
           }  
       });  
         
      });  
            function showPhotos(pic){
                var str=pic;
                alert(pic);
           $("#img_url1").fileinput({  
       language: 'zh',  
       uploadUrl: "{:U('map/upload')}", //上传后台操作的方法  
       uploadAsync: true, //设置上传同步异步 此为同步  
       maxFileSize: 800,  
       initialPreview: "<img src='"+str+"' />",
       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);
            });//初始化 后 上传插件的样子  
            }
        
            
            </script>
            
             public function getData(){
    $id=$_POST['id'];
    $arr=M("contact")->field("*")->where("id=$id")->find();
echo json_encode($arr);

 }</code>
Copy after login
Copy after login

Reply content:

<code>      我想通过以下代码初始化fileinput,后台文件也有返回值,但是现在就没法初始化,哪位高手帮我看看,谢谢!
        <script type="text/javascript">
        
        // 初始化获取原有文件  
      $(function(){  
        $.ajax({  
           type:"post",  
           url:"{:U('map/getData')}",  
           data:{id:$("#id").val()},
           dataType : "json",  
           success : function(data) { 
           alert("success"); 
           var data1=eval(data);
           alert(data1.map);
           showPhotos(data1.map);  
           },  
           error: function(XMLHttpRequest, textStatus, errorThrown) {  
                  alert(XMLHttpRequest.status);  
                  alert(XMLHttpRequest.readyState);  
                  alert(textStatus);   
           }  
       });  
         
      });  
            function showPhotos(pic){
                var str=pic;
                alert(pic);
           $("#img_url1").fileinput({  
       language: 'zh',  
       uploadUrl: "{:U('map/upload')}", //上传后台操作的方法  
       uploadAsync: true, //设置上传同步异步 此为同步  
       maxFileSize: 800,  
       initialPreview: "<img src='"+str+"' />",
       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);
            });//初始化 后 上传插件的样子  
            }
        
            
            </script>
            
             public function getData(){
    $id=$_POST['id'];
    $arr=M("contact")->field("*")->where("id=$id")->find();
echo json_encode($arr);

 }</code>
Copy after login
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!