call a jquery php function

advertisements

I'm trying to figure out the best way to do this...I am using JQuery to submit data to a PHP function, which sends back data from the DB as JSON, which is working. The thing is, on success, I want the JQuery to execute a PHP function...and I'd rather not have to make yet another AJAX call on top of the first AJAX success - especially since the php function is something I've already used elsewhere on my page. This is my code:

JQUERY:

$.ajax({
    type: "POST",
    url: post_url,
    success: function(group) //we're calling the response json array 'tree'
    {
        //WANT TO CALL THE PHP FUNCTION HERE
    } //end success
 }); //end AJAX

PHP:

<?php
foreach($groups as $group){
    echo '<option value="' . $group->id . '">' . $group->group_name . '</option>';
}
?>


In your php script that builds your response, just add an extra property to your object that is the html string you want to put into your page and then have javascript put it where it needs to go. You have no choice but to run php functions on the server.