Heim  >  Artikel  >  Backend-Entwicklung  >  php+bootstrap fileinput去上传图片,出错了,求助!

php+bootstrap fileinput去上传图片,出错了,求助!

WBOY
WBOYOriginal
2016-08-18 09:15:311551Durchsuche

<code>bug:SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.
      $("#file-5").fileinput({
        language: 'zh', //设置语言
        uploadUrl:  "{:U('profile/upload')}", // avatar_uploadyou must set a valid URL here else you will get an error __UPLOAD__partner/img
        allowedFileExtensions : ['jpg', 'png','gif'],
        overwriteInitial: false,
        maxFileSize: 1000,
        maxFilesNum: 1,
    
        //allowedFileTypes: ['image', 'video', 'flash'],
        slugCallback: function(filename) {
            alert("aaa");
            return filename.replace('(', '_').replace(']', '_');
        }
    })
     .on("fileuploaded", function (e, data) {
        var res = data.response;
        if (res.state > 0) {
            alert('上传成功');
            alert(res.path);
        }
        else {
            alert('上传失败')
        }
    });
    <form enctype="multipart/form-data">
      <hr>
                <div class="form-group">
                    <input id="file-5" class="file" type="file" multiple data-preview-file-type="any" data-upload-url="#" name="image_data">
                </div>
            </form>
            
            
            后台程序我有public function upload(){ }方法,是php的
            </code>

php+bootstrap fileinput去上传图片,出错了,求助!

出错的截图,看着似乎是语法错误,我怀疑是前台fileinput的事件那里出错了,因为后台我只返回一个值做测试,应该没问题的,对fileinput不熟,求助啊!!!谁有例子提供给我参考下也好,谢谢!

回复内容:

<code>bug:SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.
      $("#file-5").fileinput({
        language: 'zh', //设置语言
        uploadUrl:  "{:U('profile/upload')}", // avatar_uploadyou must set a valid URL here else you will get an error __UPLOAD__partner/img
        allowedFileExtensions : ['jpg', 'png','gif'],
        overwriteInitial: false,
        maxFileSize: 1000,
        maxFilesNum: 1,
    
        //allowedFileTypes: ['image', 'video', 'flash'],
        slugCallback: function(filename) {
            alert("aaa");
            return filename.replace('(', '_').replace(']', '_');
        }
    })
     .on("fileuploaded", function (e, data) {
        var res = data.response;
        if (res.state > 0) {
            alert('上传成功');
            alert(res.path);
        }
        else {
            alert('上传失败')
        }
    });
    <form enctype="multipart/form-data">
      <hr>
                <div class="form-group">
                    <input id="file-5" class="file" type="file" multiple data-preview-file-type="any" data-upload-url="#" name="image_data">
                </div>
            </form>
            
            
            后台程序我有public function upload(){ }方法,是php的
            </code>

php+bootstrap fileinput去上传图片,出错了,求助!

出错的截图,看着似乎是语法错误,我怀疑是前台fileinput的事件那里出错了,因为后台我只返回一个值做测试,应该没问题的,对fileinput不熟,求助啊!!!谁有例子提供给我参考下也好,谢谢!

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn