gpt4 book ai didi

file - 错误: Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String

转载 作者:行者123 更新时间:2023-12-02 10:42:50 30 4
gpt4 key购买 nike

我的代码有问题。
我正在尝试使用ExtJS和Codeigniter制作上传文件格式。

这是我的下面的代码,

 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字符串”。
因此,如果有人遇到相同问题或正在解决此问题,请告诉我。

谢谢!!!

结论:
哦,我懂了..
实际上,我使用Codeigniter作为框架。
如果我将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');
}
});

因此,我像这样创建我的 Controller (作为示例)。
public function upload(){
echo json_encode(1);
}

而且我的代码没有更多错误结果。
感谢Broncha!

最佳答案

您的AJAX响应不是纯JSON。尝试在控制台中输出response

success: function(response, request) {
// do whatever you need to with the generated HTML
console.log(response);
},

并检查响应是否为纯JSON

关于file - 错误: Uncaught Ext.JSON.decode(): You're trying to decode an invalid JSON String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13700824/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com