How do I construct the post data for a jQuery post? This does not work.
var postData = "";
var postInputs = document.querySelectorAll("[id^='itemInput']");
for (var i = 0; i < postInputs .length; i++) {
var itemName = postInputs [i].name;
var itemValue = postInputs [i].value ;
postData += itemName + ": '" + itemValue + "', ";
}
postData += "upload: 'Y'";
$.post("addNewItem.php", {postData},
function(data, status) {
}
);
And please if you down vote explain why.
UPDATE:
This question was closed and I was pointed to alternatives. However what I have found that works is the following. The post data needs to be a javascript object.
let postData = {}; //Create the object
item['upload'] = 'Y'; //Adding to the object ['key'] and the 'value'
var postInputs = document.querySelectorAll("[id^='itemInput']");
for (var i = 0; i < postInputs .length; i++) {
item[postInputs[i].name] = postInputs[i].value;
}
$.post("addNewItem.php", item,
function(data, status) {
}
);