1

祝大家有美好的一天,

我正在使用 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 的问题。

请建议,可能是什么问题!

4

0 回答 0