Early73
Early73

Reputation: 503

How do I send additional params with an ajax fileupload?

I'm using the html5 canvas to drag and drop file uploads but I need to send additional info with the dropped files. specifically a recordID. I'm sending my file to php like this :

canvasData = canvas.toDataURL('image/jpeg');
var ajax = new XMLHttpRequest();
ajax.open("POST", './php/uploadImage.php', false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send(canvasData);

How do I add an additional param of recordID = recordID along with the file?

Upvotes: 1

Views: 1349

Answers (2)

sebas2day
sebas2day

Reputation: 2053

I fixed it with

ajax.open("POST", './php/uploadImage.php?recordID=' + recordID, false);
ajax.setRequestHeader('Content-Type', 'application/upload');
ajax.send('recordID='+recordID+'&'+canvasData);

Upvotes: 0

Matt Ball
Matt Ball

Reputation: 359846

You can send it as a URL query parameter:

ajax.open('POST', './php/uploadImage.php?recordID' + recordID, false);

Upvotes: 1

Related Questions