jquery之a(chǎn)jax請求之load

字號:


    jquery第二十一課,ajax之load 載入遠程 html 文件代碼并插入至 dom 中
    參考共用代碼:
    <!doctype html public -//w3c//dtd html 4.0 transitional//en>
    <html><head><title>jquery特效處理-前臺代碼</title>
    <script language=javascript src=jquery-1.4.2.min.js></script>
    <script language=javascript>
    $(function(){//<!--www.forasp.cn jquery代碼區(qū)-->
    //ajax代碼區(qū)  
     });
    </script>
    <body>
    <span id=url></span>
    </body>
    </html>
    load 方法是將遠程的html文件代碼插入到對應的dom中.
    (1).load方法:load(url, [data], [callback]) 其中url是要加載的html,data是傳遞的參數(shù),格式{date:value,date:value..},callback是回調(diào)函數(shù),當加載完畢后調(diào)用該函數(shù).
    (2)load舉例
    存在1.html代碼為
    <html>
    <body>
    <b>http://www.forasp.cn/</b>
    </body>
    </html> 
    ajax的請求方法load
    $(#url).load(1.html); 結(jié)果將<b>http://www.forasp.cn/</b>加載到上面的span中
    jquery實例:參數(shù)傳遞,默認使用get方式-傳遞附加參數(shù)時自動轉(zhuǎn)換為 post 方式
    存在2.php,代碼如下:
    <?echo $_post[foraspcnurl];?>
    ajax請求方法load
    $(#url).load(2.php,{foraspcnurl:forasp.cn});這樣將foraspcnurl參數(shù)值為forasp.cn傳遞過去.在2.php接收輸出后,加載到span中
    jquery實例:參數(shù)傳遞+回調(diào)函數(shù)
    使用2.php,ajax請求如下:
    $(#url).load(2.php,{foraspcnurl:forasp.cn},function(){alert(執(zhí)行完畢);});效果跟上面的一樣只是最后彈出窗口執(zhí)行完畢.
    在load中的html中的調(diào)用當使用中文時出現(xiàn)亂碼,目前沒有解決,網(wǎng)上使用utf-8編碼即可.