I am attempting to upload a file to PHP from extjs. The file is uploading properly but the UI gets stuck and throws the following error: Uncaught You’re trying to decode and invalid JSON String:
I have searched and found suggestions to set the Content-type header to text/html but that didn’t work. Here is my code:
xtype:'form',
width:300,
bodyPadding:5,
frame:false,
items: [{
xtype: 'filefield',
name: 'csv',
msgTarget: 'side',
allowBlank: false,
buttonOnly:true,
anchor: '100%',
buttonText: 'Import CSV',
listeners: {
'change': function(fb,v){
var form = this.up('form').getForm();
form.submit({
url:'/Portal/parsecsv.php',
standardSubmit:false,
method:'PUT'
})
}
}
}]
In parsecsv.php, I simply have:
<?php header('Content-type:text/html');?>
Please assist.
The problem has been solved. The issue was that on a file upload, ExtJS by default expects a JSON response, but for some reason, ExtJS wraps the JSON response inside tags. So what I had to do is set the content-type of the response to text/html in PHP and then in ExtJS, parse the response as a String, not JSON. Also, I found that on a successful upload, ExtJS fires the “failure” event instead of the “success” event upon form submission.