Reputation: 21739
My imaginery code:
$(document).ready(function() {
$("#sub").click(function() {
info['moto'] = $("#moto").val();
info['motox'] = $("#motox").val();
$.ajax({
type: "POST",
url: "index.php",
data: "arr="+info,
success: function(msg){
$('.answer').html(msg);
}
})
})
})
How could I make, that after receiving it in .php file I could use POST method like this: $_POST['moto']
and $_POST['motox']
or something like that? What should I change? Thanks.
Upvotes: 2
Views: 10731
Reputation: 102735
Check out jQuery serialize(), it does all the work for you if you are working with form inputs.
Upvotes: 1
Reputation: 943152
Just:
data: info,
(And you need to initialize info as an object in the first place: var info = {}
)
Upvotes: 10
Reputation: 3948
I thinkyoushould go also the same way like jquery-ajax-data-array-from-php
Upvotes: 0