codeigniter中使用的ajaxFileUpload - 未执行成功函数

时间:2013-03-08 18:41:58

标签: php codeigniter jquery

大家好日子,

我正在使用ajaxFileUpload,如下所示

 $('#upload_file').submit(function(e) {
      e.preventDefault();

      $.ajaxFileUpload({
         url         :"http://localhost/CodeIgniter_Registration/index.php/application_form/file_upload",
         fileElementId  :'userfile',
         dataType    : 'json',
         data : {
            'name' : $('#document_name').val()
         },
         success  : function (data, status)
         {          
            alert(data.msg);
         }
      });
      return false;
   });

在控制器上,文件被上传,并且要返回的数据也存在

的形式返回
echo json_encode(array('status' => $status, 'msg' => $msg));

来自控制器

    function file_upload() {

        $status = "";
        $msg = "";
        $file_element_name = 'userfile';

        $config = array(
            'allowed_types' => 'jpg|jpeg|gif|png|doc|docx|pdf',
            'upload_path' => $this->gallery_path,
            'max_size' => 2000,
            'file_name' => $filename
        );

        $this->load->library('upload', $config);
        $test_upload = $this->upload->do_upload($file_element_name);

      if (!$test_upload)
      {
         $status = 'error';
         $msg = $this->upload->display_errors('', '');
      }
      else
       {
         $data = $this->upload->data();
         //$file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']);
         if(1)
         {
            $status = "success";
            $msg = "File successfully uploaded";
         }
         else
         {
            unlink($data['full_path']);
            $status = "error";
            $msg = "Something went wrong when saving the file, please try again.";
         }
      }
        @unlink($_FILES[$file_element_name]);

   echo json_encode(array('status' => $status, 'msg' => $msg));

    }

但是,似乎永远不会调用“成功”回调,也不会生成警报消息。

我也尝试过返回一些纯文本。依然没有。因此,我认为这不是json的问题。

请建议,问题是什么!!

0 个答案:

没有答案