PDA

View Full Version : File Upload response: Invalid JSON



sl5337
11 Jun 2012, 7:28 AM
When I try to upload a file in Ext JS 4.1 I receive the following Javascript error after the upload has completed. The upload itself works fine.



Uncaught Ext.Error: You're trying to decode an invalid JSON String:
ext-debug.js:6092
Ext.Error.Ext.extend.statics.raise
ext-debug.js:6092
me.decode
ext-debug.js:6264
Ext.define.handleResponse
Submit.js:255
Ext.define.processResponse
Action.js:220
Ext.define.onSuccess
Submit.js:220
Ext.apply.callback
ext-debug.js:6422
Ext.define.onUploadComplete
Connection.js:433
(anonymous function)
ext-debug.js:1815
(anonymous function)
Ext.apply.createListenerWrap.wrap


I receive this error whether or not I send back valid JSON, invalid JSON, or no response at all from the server. In the error trace above you can see that I sent back no response in this case but I get the same error even if I send back a valid JSON string. Below is my controller code for executing the file upload. You can see that I am not trying to decode anything (yet) on the client. I'm trying to get through this problem first because it is preventing my success callback function from even being called.



uploadBurnForecastFile:function(){
var uploadForm = Ext.getCmp('burnForecastUploadForm').getForm();
if (uploadForm.isValid()) {
uploadForm.submit({
url: 'uploadForecastFile.opc',
success: function(form, o){
// handle success...
},
failure:function(form, o) {
// handle failure... }
}
});
}
}


Any help with this is greatly appreciated.

sl5337
11 Jun 2012, 8:25 AM
Ok. I figured it out. I was setting the content type of the server response to "text/plain" instead of "text/html". Once I changed it to "text/html" and made sure I returned a valid response then the Javascript error went away. Sorry for the unnecessary post but perhaps someone else will run across this. :">

jambi
12 Oct 2012, 5:06 AM
FYI --- In troubleshooting this related issue, I also received the following exception (using a Chrome browser):

Unsafe JavaScript attempt to access frame with URL data:text/html,chromewebdata from frame with URL http://localhost:1527/appdir/Default.aspx (http://localhost:1527/AmbiTrack_R2_1200/accessEntrance.aspx#NpaDetailsTabPanel:NpaPhaseMetaTab) Domains, protocols and ports must match.

In my specific scenario, I received this when trying to upload files greater than the configured maximum file size. In my case, the default max file size allowed to transfer was 4MB.