网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 jquery之ajax请求之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代码区-->
    //ajax代码区  
     });
    </script>
    <body>
    <span id=url></span>
    </body>
    </html>
    load 方法是将远程的html文件代码插入到对应的dom中.
    (1).load方法:load(url, [data], [callback]) 其中url是要加载的html,data是传递的参数,格式{date:value,date:value..},callback是回调函数,当加载完毕后调用该函数.
    (2)load举例
    存在1.html代码为
    <html>
    <body>
    <b>http://www.forasp.cn/</b>
    </body>
    </html> 
    ajax的请求方法load
    $(#url).load(1.html); 结果将<b>http://www.forasp.cn/</b>加载到上面的span中
    jquery实例:参数传递,默认使用get方式-传递附加参数时自动转换为 post 方式
    存在2.php,代码如下:
    <?echo $_post[foraspcnurl];?>
    ajax请求方法load
    $(#url).load(2.php,{foraspcnurl:forasp.cn});这样将foraspcnurl参数值为forasp.cn传递过去.在2.php接收输出后,加载到span中
    jquery实例:参数传递+回调函数
    使用2.php,ajax请求如下:
    $(#url).load(2.php,{foraspcnurl:forasp.cn},function(){alert(执行完毕);});效果跟上面的一样只是最后弹出窗口执行完毕.
    在load中的html中的调用当使用中文时出现乱码,目前没有解决,网上使用utf-8编码即可.
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/21 2:27:21