In "How jquery implements ajax technology 1: $.ajax()" we have learned how to use jQuery's $.ajax() function to achieve ajax development needs. But compared to some other functions, the implementation process and code amount of $.ajax() are still relatively complicated.
Today we will learn about jQuery’s $.post() function. Compared with the $.ajax() function, the $.post() function is simpler and more convenient, but it can only submit data parameters to the PHP file you need to access virtually through POST.
Let’s first take a look at the parameters in the $.post() function:
$.post(url,data,callback,type)
url---The URL address of the page to be loaded.
data---Key / value parameters to be sent.
callback---Callback function when loading is successful.
type---Return content format, xml, html, script, json, text, _default.
Here is a practical example:
============================================ =====================
ajax.html
$(document).ready(function(){
$('#bot_1').click(function(){
$.post('ajax.php' ,{web:"mysql100"},function(data,st){$("div").html(data);})
})
})
head>
========= ================================================== ====
ajax.php
echo 'The website you want to visit is'.$_POST['web'];
?>
The above is how jquery implements ajax Technology 2: Content of $.post(), please pay attention to the PHP Chinese website (www.php.cn) for more related content!