我的代碼存在問題。 我正在嘗試使用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 !!