file upload seems to NOT go thru the ajax data function
file upload seems to NOT go thru the ajax data function
In the editor setup, I have set the ajax and ajax.data as follows:
ajax: {
url: ajax_url,
type: 'POST',
data: function (d) {
d.datatable_action = d.action;
d.action = 'ticket' ;
d.subaction = 'images';
}
}
I need to do it this way because it is part of a Wordpress system which everything is routed thru the central ajax program.
I used this method to get it properly routed to my handler which in there will set the "action" variable back to the correct action.
However, when I tried to use the uploadMany field types, it caused problems.
I have configured the Editor fields as follows:
{
'label': 'Panel Symptom Photo:',
'name': 'panel_symptom_photo.files',
'type': 'uploadMany'
}
When I drag a file to do the upload, it does not do anything. I put on a 'preUpload' event listener to trap the ajaxData to check what is going on.
editor.on('preUpload', function (e, fieldName, file, ajaxData) {
for (var pair of ajaxData.entries()) {
console.log(pair[0]+': '+pair[1]) ;
}
return true;
})
And the following result was logged on the console:
action: upload
uploadField: panel_symptom_photo.files
upload: [object File]
datatable_action: undefined
action: ticket
subaction: images
Please note that there are TWO 'action' field in there, which the first one should be put into 'datatable_action'.
Please advise what should I do.
Thanks
Jim
Answers
Alright, found the problem and the workaround.
There seems to be several issues there:
The following was done to get it to be more compatible with other ajax actions:
Regards
Jim
Silly me!!
An alternate solution that does NOT involve change the distribution files is to use the 'preUpload' event handler, and modify the ajaxData before the actual submission.
Cheers
Excellent, glad all sorted,
Colin