Ajax中的load()方法實現指定地區載入或重新整理html與jsp

來源:互聯網
上載者:User

標籤:val   getjson   完成   head   col   png   utf-8   com   not   

梳理知識方法的時候,筆者還是有數的,就不閑扯了。
一、Jquery中的Ajax
Jquery對Ajax操作進行了封裝,在Jquery中:
最底層的是$.ajsx(),
第二層是load()、$.get()、$.post()
第三層是$.getJSON()
二、load()方法(能載入遠程html、jsp代碼,插入到DOM中)
load()方法是Jquery中最簡單和常用的Ajax方法,能載入遠端html。
它的結構:
load(url,data,callback);
url:請求html、jsp頁面的url-String
data(可選):發送到伺服器的key/value資料-Objext
callback(可選):請求完成是的回呼函數,無論請求成功或失敗-function。
它的傳遞參數比較智能了:無發送伺服器的參數,採用Get方式,否則是post的方式
三、貼出代碼:
<!DOCTYPE html>

<html>    <head>        <meta charset="UTF-8">        <script type="text/javascript" src="js/jquery.js" ></script>        <title>淺析Ajax的使用</title>    </head>    <body>        <a onclick="load_other_html()">點我載入</a>        <div id="20180825"><div>    </body>    <script>        function load_other_html(){            //使用load,載入遠程html代碼至div中            $("#20180825").load("20180825.html",function(data, textStatus,xmlRequest){                /*function裡麵包含三個參數:                 * 1、返回請求的內容data                 * 2、請求返回的狀態:是否成功:success、error、notmodify、timeout                 * 3、Xml請求對象                 */            })        }    </script></html>

在20180825.html中,簡單定義一下:

    <!DOCTYPE html>    <html>        <head>            <meta charset="UTF-8">            <title></title>        </head>        <body>            <h1>大家好,我是20180825.html頁面</h1>        </body>    </html>

Ajax中的load()方法實現指定地區載入或重新整理html與jsp

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.