I am looping through several inputs and trying to append that data into an object which I can then pass into an AJAX function. I’m not quite sure what I’m doing wrong, but I keep getting an error that says "Uncaught SyntaxError: Unexpected token )", and I can’t find this extra bracket, and I think I must just be doing this incorrectly.
var dataObject = [];
$("#"buttonId).find("input").each(function(index) {
inputId = $(this).attr("id").replace(buttonId, "");
inputValue = $(this).val();
var data = {
inputId : inputValue;
}
dataObject.push(data);
});
$.post(
'ajax/' + buttonId + '.php',
{
dataObject: dataObject
},
function (response) {
}
);
You are missing
+for string concatenation.Also you cannot use a variable as a property name in object literal, try this:
You can also use
mapmethod:Or .serializeArray() method.