0

All, I have the following code:

$.post("save.php", {rate: value, vendor: vendor_id}, function(results)
{
    alert(results);
}, "json");

I get the data and do some updates to the database. When I'm done I'd like to pass back $var1, $var2. Then parse those values and put them into a div. How can I send these values back so I can access them in something like:

results.var1

Then I can put that value of var1 into a div. Thanks for the help!

2 Answers 2

2

You would create an associative array holding your data, turn it into JSON and return it:

$data = array('var_one' => $var1, 'var_two' => $var2);
$jsonData = json_encode($data);
echo $jsonData;

You can read about manipulating elements with jQuery to learn about inputting the data into your HTML.

Sign up to request clarification or add additional context in comments.

Comments

0

In your php script, you would have to put $var1 and $var2 in a json object and echo out that object.

The easiest way to do that would be to put $var1 and $var2 in an array and do an echo json_encode($arr);

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.