I have a form that have several inputs. Some of them are stored in an array. When I use the ajax function to send them to the PHP script, I can get all the values from the inputs but the array object will echo 'Array'.
$('#Save').click(function(){
var Name = $('#Name').val();
var Type = $('select#Type selected:option').attr('value');
var Values = new Array(1, 2, 4);
$.ajax({
url: 'GetValues.php',
type: 'POST',
data: {Name: Name, Type: Type, Values: Values}
});
});
PHP Script:
$Name = $_POST['Name']; //echo the names.
$Type = $_POST['Type']; //echo the type.
$Values = $_POST['Values']; // echo 'Array' ?
I have tried to use JSON_decode but still can't get the values from the form. Any ideas? Thank you
print_r($Values)
and let me know if that prints your array or not.. – asifrc Jan 17 at 23:41selected:option
should beoption:selected
. But you really should just use$("#Type").val()
. – Barmar Jan 17 at 23:45