0

Given the following jquery:

$.post(path, {one:'alex', two:'thomas'}, function (response) {
    alert(response);
});

And the following PHP:

<?php
  $first = $_POST['one'];
  echo $first;
?>

How do I get it to return a response?

It works fine if I send just one variable:

$.post(path, 'one=alex', function (response) {
    alert(response);
});

Thanks

1 Answer 1

3

Use json.

$response = array(
    'first' => $response1,
    'second' => $response2
);
echo json_encode($response);

$.post(path, 'one=alex', function (response) {
    response = JSON.parse(response );
    alert(response.first);
});
Sign up to request clarification or add additional context in comments.

4 Comments

@AlexThomas this answers your question; the data being sent was just mis-typed by John. +1, John.
Not sure I follow, how am i passing the valuse to my php file? It looks like you're only sending one 'one=alex'
Got there in the end... I'll except your answer as soon as i can
You should write your results as formatted in a language that javascript can parse. JSON is good for this. You can also use XML.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.