0

i have this code:

function Save(whichOne){
    var name = $('#name').val();
    var surname = $('#surname').val();
    $.ajax({
        url: 'SaveEntry.php',
        type: 'post',
        data: { "callFunc1": whichOne},
        success: function(response) {
            alert(response);
        }
    });
}

I want to do something like this:

function Save(whichOne){
    var name = $('#name').val();
    var surname = $('#surname').val();
    $.ajax({
        url: 'SaveEntry.php',
        type: 'post',
        data: { "callFunc1": {whichOne, name, surname}},
        success: function(response) {
            alert(response);
        }
    });
}

But it does not work. The problem is in this line:

data: { "callFunc1": {whichOne, name, surname}},

How do i post multiple values?

EDIT: I am getting this error: Warning: missing argument 2 for func1()

and i have this code:

if (isset($_POST['callFunc1'])) {
    echo func1($_POST['callFunc1']);
}
3
  • What is the error message you get? Commented Apr 10, 2015 at 11:30
  • @martin Warning: missing argument 2 for func1() Commented Apr 10, 2015 at 14:02
  • you should pass the name value pairs then use the PHP to put the returns into the function. Commented Apr 10, 2015 at 14:08

2 Answers 2

3

You need key value pairs unless you want to send JSON data:

data: { "callFunc1": whichOne, "name": name, "surname":surname}
Sign up to request clarification or add additional context in comments.

1 Comment

i am getting this error: Warning: missing argument 2 for func1()
0

Depends on what you want to pass. It's either

data: [whichOne, name, surname] - that would be an array

or it's an object

data: { "whichOne" : whichOne, "name" : name, "surname" : surname }

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.