What is the best way to create an HTTP request using JavaScript that sends a file and some post data to a PHP server?
I came across the following code snippet, but it appears to be incomplete.
xhr.open("POST", "upload.php");
var boundary = '---------------------------';
boundary += Math.floor(Math.random()*32768);
boundary += Math.floor(Math.random()*32768);
boundary += Math.floor(Math.random()*32768);
xhr.setRequestHeader("Content-Type", 'multipart/form-data; boundary=' + boundary);
var body = '';
body += 'Content-Type: multipart/form-data; boundary=' + boundary;
// more code here...
In order to make this work successfully, how do I include additional post data along with the file? I want to send a description text as well. It seems like I would need to use xhr.send to send the complete request...