php - Ext.JSON.decode(): You're trying to decode an invalid JSON String 访问/source/index.php/file/upload/时出现问题
问题描述
提交我的 ExtJS 表单后出现以下错误
安慰:
Ext.JSON.decode(): You're trying to decode an invalid JSON String 访问/source/index.php/file/upload/时出现问题
JS 控制器文件:
uploadFile: function (button, e, eOpts) {
var form = button.up('form');
if(form.isValid()){
form.submit({
url: 'source/index.php/file/upload/',
waitMsg: 'Upload Gambar',
success: function(fp, o) {
if(o.result.success == 'true'){
Ext.Msg.alert('Sukses', 'Gambar Anda "' + o.result.file + '" Telah Diunggah.');
}else{
Ext.Msg.alert('Error', 'Ada Kesalah, Mohon Di Cek Kembali');
}
//console.log(o.result);
}
});
}
}
PHP Codeigniter 文件有:
public function upload(){
$answer = array("success"=>"false");
$flag = true;
$error=array();
$info=array();
$config=array();
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload("imagen")) //falta modificar la foto para que encaje con el numero de dni
{
$error = array('error' => $this->upload->display_errors());
}
else
{
$info=$this->upload->data();
$name= $info['file_name'];
$tmp= $info['full_path'];
$sql= "insert into file (id,name,data) values (NULL,'".$name."', load_file('".$tmp."') );";
$answer = array("success"=>"true","file"=>$name);
$this->model_file->execute($sql);
}
header("Content-Type: application/json; charset=utf-8");
echo json_encode($answer);
}
存储 JS:
proxy: {
type:'ajax',
api:{
create: 'source/index.php/file/create',
read: 'source/index.php/file/all',
update: 'source/index.php/file/update',
destroy: 'source/index.php/file/delete'
},
reader:{
type: 'json',
rootProperty: 'data'
},
writer: {
type:'json',
rootProperty: 'data',
writeAllFields: true,
encode: true,
allowSingle: true
}
},
解决办法是什么?我正在使用 Ext JS 6 和 Codeigniter 框架
解决方案
推荐阅读
- bash - 我们可以将 IFS 设置为一个数字范围吗?
- list - 接口列表的目的是什么:列表
? 是不好的做法吗? - python - Pandas - 在 pandas.DataFrame() 中使用具有大量缺失值的数据强制执行自动数据类型
- angular - Angular 环境中的 Prolifics Panther
- javascript - 如果子组件发生更改,如何重新渲染父组件
- google-apps-script - 修改 SendGoogleForm 脚本
- xamarin - 是否可以弹出一个模式页面然后立即推送一个新页面?
- servicenow - 使用 RET API 在 servicenow 中检索查询字符串的 KB 文章的请求、响应 JSON 格式
- java - 如何在 IntelliJ 中获取 SonarLint 问题统计信息
- r - 在单击左侧边栏菜单项时激活/停用闪亮仪表板右侧栏中的选项卡