国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery - AJAX 簡介

什么是 AJAX ?

AJAX = 異步 JavaScript 和 XML(Asynchronous JavaScript and XML)。

AJAX 是一種用于創(chuàng)建快速動態(tài)網(wǎng)頁的技術(shù)。

通過在后臺與服務(wù)器進(jìn)行少量數(shù)據(jù)交換,AJAX 可以使網(wǎng)頁實現(xiàn)異步更新。這意味著可以在不重新加載整個網(wǎng)頁的情況下,對網(wǎng)頁的某部分進(jìn)行更新。

傳統(tǒng)的網(wǎng)頁(不使用 AJAX)如果需要更新內(nèi)容,必需重載整個網(wǎng)頁面。

有很多使用 AJAX 的應(yīng)用程序案例:新浪微博、Google 地圖、開心網(wǎng)等等。

關(guān)于 jQuery 與 AJAX

JQuery是輕量級的js庫,它兼容CSS3,還兼容各種瀏覽器 (IE 6.0+, FF1.5+, Safari 2.0+, Opera 9.0+)。jQuery使用戶能更方便地處理HTML documents、events、實現(xiàn)動畫效果,并且方便地為網(wǎng)站提供AJAX交互。

通過 jQuery AJAX 方法,您能夠使用 HTTP Get 和 HTTP Post 從遠(yuǎn)程服務(wù)器上請求文本、HTML、XML 或 JSON - 同時您能夠把這些外部數(shù)據(jù)直接載入網(wǎng)頁的被選元素中。


實例:

先展示一個前端代碼:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>php中文網(wǎng)(php.cn)</title>
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            //按鈕單擊時執(zhí)行
            $("#testAjax").click(function(){
                //Ajax調(diào)用處理
                var html = $.ajax({
                    type: "POST",
                    url: "text.php",
                    data: "name=garfield&age=18",
                    async: false
                }).responseText;
                $("#myDiv").html('<h2>'+html+'</h2>');
            });
        });
    </script>
</head>
<body>
<div id="myDiv"><h2>通過 AJAX 改變文本</h2></div>
<button id="testAjax" type="button">Ajax改變內(nèi)容</button>
</body>
</html>

在展示一段后臺php代碼,我們給命名為text.php:

<?php
  $msg='Hello,'.$_POST['name'].',your age is '.$_POST['age'].'!';
  echo $msg;
?>

這樣我們就完成一個JQuery 簡單的 ?Ajax調(diào)用實例。

繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>php中文網(wǎng)(php.cn)</title> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ //按鈕單擊時執(zhí)行 $("#testAjax").click(function(){ //Ajax調(diào)用處理 var html = $.ajax({ type: "POST", url: "text.php", //調(diào)用text.php data: "name=garfield&age=18", async: false }).responseText; $("#myDiv").html('<h2>'+html+'</h2>'); }); }); </script> </head> <body> <div id="myDiv"><h2>通過 AJAX 改變文本</h2></div> <button id="testAjax" type="button">Ajax改變內(nèi)容</button> </body> </html>
提交重置代碼