2

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

3 Answers 3

10

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

serialize is nice but i found it make more work when dealing with degradation
0

I thinkyoushould go also the same way like jquery-ajax-data-array-from-php

answered Apr 23, 2011 at 22:11

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.