Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未捕获的语法错误:使用jQuery插件的意外令牌x?_Javascript_Php_Jquery_Json_Uploadify - Fatal编程技术网

Javascript 未捕获的语法错误:使用jQuery插件的意外令牌x?

Javascript 未捕获的语法错误:使用jQuery插件的意外令牌x?,javascript,php,jquery,json,uploadify,Javascript,Php,Jquery,Json,Uploadify,我目前正在使用uploadify jQuery插件将图像上传到文件夹。图像上传部分工作正常,但当我尝试添加额外的表单数据时,它会给我错误Uncaught SyntaxError:Unexpected token x 我正在以JSON数组的形式检索数据,我的响应头内容类型是application/JSON,但不确定它为什么会抛出此错误 我的问题是:根据下面的代码,为什么会发生这个错误,解决方案是什么 jQuery: $('#userfile').uploadify({

我目前正在使用uploadify jQuery插件将图像上传到文件夹。图像上传部分工作正常,但当我尝试添加额外的表单数据时,它会给我错误
Uncaught SyntaxError:Unexpected token x

我正在以JSON数组的形式检索数据,我的响应头内容类型是
application/JSON
,但不确定它为什么会抛出此错误

我的问题是:根据下面的代码,为什么会发生这个错误,解决方案是什么

jQuery:

          $('#userfile').uploadify({
                'auto':false,
                'swf': base_url + 'assets/js/jquery/uploadify_31/uploadify.swf',
                'uploader': base_url + 'post/cover_upload',
                'cancelImg': base_url + 'assets/jquery/uploadify-cancel.png',
                'fileTypeExts':'*.jpg;*.bmp;*.png;*.tif;*.gif;*.jpeg',
                'fileTypeDesc':'Image Files (.jpg,.bmp,.png,.tif,.gif,.jpeg)',
                'fileSizeLimit':'10MB',
                'fileObjName':'userfile',
                'buttonText':'Select Photo(s)',
                'multi':true,
                'removeCompleted':false,
                'onUploadSuccess' : function(file, data, response) {
                    var responseObj = JSON.parse(data);
                    if(responseObj.file_name){
                        $('#cover-image').css("background-image", "url('http://localhost:8888/SimpleBlog/uploads/"+responseObj.file_name+"')");     
                        $('#cover-image').css("background-size", "cover");
                        $('#cover-image').css("background-position", "center");
                    }
                },
                'onUploadStart' : function(file) {
                    var uri = window.location.pathname.split('/').pop();
                    $('#userfile').uploadify("settings", 'formData', {'pst_str' : uri});
                }
            });
PHP-发布/封面上传

public function cover_upload(){

    $this->load->library('upload');

    $image_upload_folder = FCPATH . '/uploads';

    if (!file_exists($image_upload_folder)) {
        mkdir($image_upload_folder, DIR_WRITE_MODE, true);
    }

    if($this->input->post('pst_str') == "add"){
        $pst_str = $this->create_temp_post();
    }else{
        $pst_str = $this->input->post('pst_str');
    }

    $this->upload_config = array(
        'upload_path'   => $image_upload_folder,
        'allowed_types' => 'png|jpg|jpeg|bmp|tiff',
        'max_size'      => 36000,
        'max_width'     => 10240,
        'max_height'    => 7680,
        'remove_space'  => TRUE,
        'file_name'     => random_string('alnum', 16),
        'pst_str'       => $pst_str
    );

    $this->upload->initialize($this->upload_config);

    if ( !$this->upload->do_upload() ) {
        $upload_error = $this->upload->display_errors();
        echo json_encode($upload_error);
    }else{
        header("content-type:application/json");

        $file_info = $this->upload->data();
        $this->post_model->add_cover($pst_str, $file_info['file_name']);

        echo json_encode($file_info);

    }

}

非常感谢您的帮助。

这似乎就是您的JSON格式。尝试以这种方式解析您的响应

   if(data.file_name){
     $('#cover-image').css("background-image", "url('http://localhost:8888/SimpleBlog/uploads/"+data.file_name+"')");     
      $('#cover-image').css("background-size", "cover");
      $('#cover-image').css("background-position", "center");
    }

您的数据响应是什么样子的?比如
{“client\u name”:“banana gif.jpg”,“file\u ext”:.jpg”,“file\u name”:“Rl4dmhySHWgrAsH6.jpg”,“file\u path”:“\/Applications\/MAMP/htdocs\/SimpleBlog\/uploads\/22.85”,“file\u type”:“image/jpeg”,“full\u path”:“\/Applications\/MAMP\/htdocs\/SimpleBlog\/uploads\/Rl4dmhySHWgrAsH6.jpg”,“图像高度”:“534”,“图像大小”:“宽度=”950“高度=”534\”,“图像类型”:“jpeg”,“图像宽度”:“950”,“是图像”:真,“原始名称”:“Rl4dmhySHWgrAsH6.jpg”,“原始名称”:“Rl4dmhySHWgrAsH6”};