FairyBusiness
asked on
When I push data into my serialized array in jquery it's not being recognized in my php function?
Hi, I am trying to push data into a serialized array that I have, and even though it's making its way into my ajax call, it's coming up as undefined in my php. Mind you, these are values from file input fields (if that makes a difference... its the reason I have to manually push them bc they won't be serialized otherwise). Anyone know why my php might not like this??
javascript:
javascript:
var addProduct = function (e) {
e.preventDefault();
var data = $('#addProductForm').serializeArray();
data.push({ addProductForm: true });
data.push({ primary: $('input[name="primary"]').val().split('\\')[2] });
data.push({ other1: $('input[name="other1"]').val().split('\\')[2] });
data.push({ other2: $('input[name="other2"]').val().split('\\')[2] });
data.push({ other3: $('input[name="other3"]').val().split('\\')[2] });
data.push({ other4: $('input[name="other4"]').val().split('\\')[2] });
$.ajax({
type: 'Post',
url: 'includes/library.php',
data: data,
success: function(result) {
console.log(result);
},
error: function(result) {
console.log(result);
}
});
};
php:if (isset($_POST['title'])) {
$output = '';
foreach ($_POST as $key => $value) {
$output .= $key . ": " . $value . "<br />";
}
echo $output;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER