Home  >  Article  >  Backend Development  >  Something went wrong when using php+bootstrap fileinput to upload images, please help!

Something went wrong when using php+bootstrap fileinput to upload images, please help!

WBOY
WBOYOriginal
2016-08-18 09:15:311582browse

<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>

Something went wrong when using php+bootstrap fileinput to upload images, please help!

The screenshot of the error seems to be a syntax error. I suspect that there is an error in the fileinput event in the foreground. Because I only return one value in the background for testing, it should be fine. I am not familiar with fileinput. Please help! ! ! If anyone has an example for me to refer to, thank you!

Reply content:

<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>

Something went wrong when using php+bootstrap fileinput to upload images, please help!

The screenshot of the error seems to be a syntax error. I suspect that there is an error in the fileinput event in the foreground. Because I only return one value in the background for testing, it should be fine. I am not familiar with fileinput. Please help! ! ! If anyone has an example for me to refer to, thank you!

Statement:
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