开发者

Posting with jQuery

How would I do this开发者_如何学Python 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.


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 */
    }
);


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.


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
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜