views:

137

answers:

3

How would I do this in jquery? I would like to post data, process, and then retrieve the page that is generated by that data.

All I can find are seperate just post. or just retrieve data.

+6  A: 

jQuery has the jQuery.post method to do that:

jQuery.post(
    'http://example.com/…',
    {/* post data of key-value pairs */},
    function(data, textStatus) {
        /* callback function to process the response */
    }
);
Gumbo
+4  A: 

To post the data you use $.post. The return value would be in the first parameter of the calback function.

For example:

$.post('urlToPostTo', null, function(data){
   alert(data);
}

This will show the returned data from the server in an alert box.

Geoff
+1  A: 

You might as well try this example:

Client Side:

Search: <input type="text" id="criteria" />
<button id="searchButton">Go</button>
<div id="results">
</div>

<script>
    var q = $('#criteria').val();    
    $.post('search.php',{'query':q},function(result){
        $('#results').html(result);
    });
</script>

Server Side(search.php):

<?php        
    $q = $_ POST['query'];
    //do some query on db
    //display the results
    //do some print
?>
jerjer