I have a form with a filefield I want to upload to a NodeJS + Express server. I managed sending the file to my server using form.submit but the thing is I can't get a successful response from it...the message I get looks like this
{success:false,message:"Blocked a frame with origin "http://localhost:1841" from accessing a cross-origin frame."}
I managed avoiding this message and getting a successful return in some other places using JSONP requests, but I can't figure out how to solve this when trying to upload a file. Is there any way to upload a file using JSONP?
I tried enabling CORS in my NodeJS + Express backend but with no success (I used express-cors and cors modules), I get the same failure message.
This is what my submit function looks like
me.up('form').submit({
url:'http://localhost:3000/parseExcel',
waitMsg:'Leyendo archivo...',
success:function(form, resp){
console.log(resp);
var data = JSON.parse(resp);
console.log(data);
},
failure:function(form, o){
console.log(form)
console.log(o)
}
})
And this is the backend function that is called on the form submit
router.post('/parseExcel', function(req, res){
var obj = xlsx.parse(req.files.fileupload.path);
var data = obj[0].data;
var result = {
success:true,
data:data
}
var callback = req.query.callback;
if (callback) {
res.setHeader('Content-Type', 'text/javascript');
res.send(callback + '(' + JSON.stringify(result) + ')');
} else {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(result));
};
})