jQuery 使用手册(七)

2020-05-24 21:19:44易采站长站整理

:Ajax支持

 通用方式:
$.ajax(prop)    通过一个ajax请求,回去远程数据,prop是一个hash表,它可以传递的key/value有以下几种
         (String)type:数据传递方式(get或post)。
         ((String)url:数据请求页面的url
         ((String)data:传递数据的参数字符串,只适合post方式
         ((String)dataType:期待数据返回的数据格式(例如 “xml”, “html”, “script”,或 “json”)
         ((Boolean)ifModified: 当最后一次请求的相应有变化是才成功返回,默认值是false
         ((Number)timeout:设置时间延迟请求的时间。可以参考$.ajaxTimeout
         ((Boolean)global:是否为当前请求触发ajax全局事件,默认为true
         ((Function)error:当请求失败时触发的函数。
         ((Function)success:当请求成功时触发函数
         ((Function)complete:当请求完成后出发函数
jQuery代码及说明
$.ajax({url: “ajax.htm”,
          success:function(msg){ 
                         $(div”#a”).html(msg);
                } 
    });将ajax.htm返回的内容作为id为a的div内容
$.ajax({ url: “ajax.aspx”,
              type:”get”,           
             dataType:”html”,
             data: “name=John&location=Boston”,
             success:function(msg){ 
                                 $(“#a”).html(msg);
                              } 
         });