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.
asked Apr 23, 2011 at 22:08
good_evening
21.9k70 gold badges203 silver badges307 bronze badges
3 Answers 3
Just:
data: info,
(And you need to initialize info as an object in the first place: var info = {})
answered Apr 23, 2011 at 22:12
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Check out jQuery serialize(), it does all the work for you if you are working with form inputs.
answered Apr 23, 2011 at 22:12
No Results Found
103k38 gold badges199 silver badges232 bronze badges
1 Comment
mcgrailm
serialize is nice but i found it make more work when dealing with degradation
I thinkyoushould go also the same way like jquery-ajax-data-array-from-php
answered Apr 23, 2011 at 22:11
Reporter
3,9345 gold badges36 silver badges50 bronze badges
Comments
default