我的代码存在问题。 我正在尝试使用ExtJS和Codeigniter进行上传文件格式。错误:Uncaught Ext.JSON.decode():您试图解码无效的JSON字符串
这里是我下面的代码,
Ext.require([
'Ext.form.field.File',
'Ext.form.Panel',
'Ext.window.MessageBox'
]);
Ext.onReady(function(){
Ext.create('Ext.form.Panel', {
title: 'Upload a Photo',
width: 400,
bodyPadding: 10,
frame: true,
renderTo: Ext.getBody(),
items: [{
xtype: 'filefield',
name: 'photo',
fieldLabel: 'Photo',
labelWidth: 50,
msgTarget: 'side',
allowBlank: false,
anchor: '100%',
buttonText: 'Select Photo...'
}],
buttons: [{
text: 'Upload',
handler: function() {
var form = this.up('form').getForm();
if(form.isValid()){
form.submit({
url: '../upload',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
Ext.Ajax.request({
url: o.data.url,
method: "GET",
success: function(response, request) {
// do whatever you need to with the generated HTML
alert(response.responseText);
},
failure: function(response, request) {
alert('failed');
}
});
}
});
}
}
}]
});
});
但像显示我的错误控制台输出“未捕获Ext.JSON.decode():你试图解码的JSON字符串无效”。 因此,如果任何人有同样的问题或正在解决这个问题,请告诉我..
谢谢!
结论: 哦,我看.. 其实我用笨作为我的框架。 如果我返回JSON这个网址这个问题将得到解决..
url: '../upload',
waitMsg: 'Uploading your photo...',
success: function(fp, o) {
Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.');
Ext.Ajax.request({
url: o.data.url,
method: "GET",
success: function(response, request) {
// do whatever you need to with the generated HTML
alert(response.responseText);
},
failure: function(response, request) {
alert('failed');
}
});
所以,我创造我的控制器是这样的(如样品)..
public function upload(){
echo json_encode(1);
}
并没有更多的错误结果我代码.. THANKS Broncha !!