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.

3 Answers 3

10

Just:

data: info,

(And you need to initialize info as an object in the first place: var info = {})

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.

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

Comments

Your Answer

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.