I'm trying to send a JavaScript Object() to a PHP file in the correct format that $.POST wants. The PHP file doesn't set any $_POST[] variables so i must be sending it in an incorrect format.
JS:
$('#downloadBtn').click(function(){
var form_data = new Object();
form_data.filepath = $("#fileName").html();
$.post(
"/UpdateDownloads.php",
{ JSON.stringify(form_data) },
function(data) {
alert(data);
}
);
});
I know that changing the sent data to "{ filepath: form_data.filepath }" will fix the problem, but this is a sloppy fix because it doesn't change as i add more and more data to form_data. Basically im wondering if there is a JS function that can transform my Object() variable into a form which POST will accept and set the $_POST['filepath'] variables that i add to my form_data Object().