jQuery Ajax 全解析

openkk 12年前
     <p>jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯。</p>    <p>废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是对jQuery.ajax()进行封装以方便我们使用的方法,当然,如果要处理复杂的逻辑,还是需要用到jQuery.ajax()的(这个后面会说到).</p>    <p><span style="font-size:medium;"><span style="color:#bb0000;"><strong>1. load</strong>( url, [data], [callback] ) :载入远程 HTML 文件代码并插入至 DOM 中。</span></span></p>    <p><strong>url </strong>(String) : 请求的HTML页的URL地址。 </p>    <p><strong>data </strong>(Map) : (可选参数) 发送至服务器的 key/value 数据。 </p>    <p><strong>callback </strong>(Callback) : (可选参数) 请求完成时(<span style="color:#bb0000;">不需要是success的</span>)的回调函数。 </p>    <p>这个方法默认使用 GET 方式来传递的,如果[data]参数有传递数据进去,就会自动转换为POST方式的。jQuery 1.2 中,可以指定选择符,来筛选载入的 HTML 文档,DOM 中将仅插入筛选出的 HTML 代码。语法形如 "url #some > selector"。</p>    <p>这个方法可以很方便的动态加载一些HTML文件,例如表单。</p>    <p>示例代码:</p>    <pre>$("<span style="color:#8b0000;">.ajax.load</span>").load("<span style="color:#8b0000;">http://www.cnblogs.com/QLeelulu/archive/2008/03/30/1130270.html .post</span>",   <span style="color:#0000ff;">function</span> (responseText, textStatus, XMLHttpRequest){   <span style="color:#0000ff;">this</span>;<span style="color:#008000;">//在这里this指向的是当前的DOM对象,即$(".ajax.load")[0]</span>    <span style="color:#008000;">//alert(responseText);//请求返回的内容</span>   <span style="color:#008000;">//alert(textStatus);//请求状态:success,error</span>   <span style="color:#008000;">//alert(XMLHttpRequest);//XMLHttpRequest对象</span> });</pre>    <div class="ajax load">     这里将显示结果。    </div>    <p> </p>    <p><strong><span style="color:#bb0000;">注:</span></strong>不知道为什么URL写绝对路径在FF下会出错,知道的麻烦告诉下。下面的get()和post()示例使用的是绝对路径,所以在FF下你将会出错并不会看到返回结果。<span style="color:#ff00ff;">还有get()和post()示例都是跨域调用的,发现传上来后没办法获取结果,所以把运行按钮去掉了。</span> </p>    <p>  </p>    <p><span style="font-size:medium;"><span style="color:#bb0000;"><strong>2. jQuery.get</strong>( url, [data], [callback] ):使用GET方式来进行异步请求</span></span> </p>    <blockquote>     <p>参数: </p>     <p><strong>url </strong>(String) :  发送请求的URL地址. </p>     <p><strong>data </strong>(Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示,会做为QueryString附加到请求URL中。 </p>     <p><strong>callback </strong>(Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。</p>    </blockquote>    <p>这是一个简单的 GET 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。示例代码: </p>    <pre>  $.get("<span style="color:#8b0000;">./Ajax.aspx</span>", {Action:"<span style="color:#8b0000;">get</span>",Name:"<span style="color:#8b0000;">lulu</span>"}, <span style="color:#0000ff;">function</span> (data, textStatus){     <span style="color:#008000;">//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.</span>     <span style="color:#0000ff;">this</span>; <span style="color:#008000;">// 在这里this指向的是Ajax请求的选项配置信息,请参考下图</span>     <span style="color:#0000ff;">alert</span>(data);     <span style="color:#008000;">//alert(textStatus);//请求状态:success,error等等。                                   当然这里捕捉不到error,因为error的时候根本不会运行该回调函数</span>     <span style="color:#008000;">//alert(this);</span>   });</pre>    <p>点击发送请求: </p>    <p>jQuery.get()回调函数里面的 this ,指向的是Ajax请求的选项配置信息: </p>    <p><a href="https://simg.open-open.com/show/ee196cb49e825046ba09c7307d2e41fe.png" rel="nofollow"><img alt="jQuery Ajax 全解析" src="https://simg.open-open.com/show/77575859a0bf46d80fa550386565169e.png" width="466" height="289" /></a> </p>    <p>  </p>    <p><span style="font-size:medium;"><span style="color:#bb0000;"><strong>3. jQuery.post</strong>( url, [data], [callback], [type] ) :使用POST方式来进行异步请求</span></span> </p>    <blockquote>     <p>参数: </p>     <p><strong>url </strong>(String) : 发送请求的URL地址. </p>     <p><strong>data </strong>(Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。 </p>     <p><strong>callback </strong>(Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。</p>     <p><strong>type</strong> (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)</p>    </blockquote>    <p>这是一个简单的 POST 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。示例代码:</p>    <p>Ajax.aspx:</p>    <pre>Response.ContentType = "<span style="color:#8b0000;">application/json</span>"; Response.Write("<span style="color:#8b0000;">{result: '</span>" + Request["<span style="color:#8b0000;">Name</span>"] + "<span style="color:#8b0000;">,你好!(这消息来自服务器)'}</span>");</pre>jQuery 代码:    <pre>$.post("<span style="color:#8b0000;">Ajax.aspx</span>", { Action: "<span style="color:#8b0000;">post</span>", Name: "<span style="color:#8b0000;">lulu</span>" },   <span style="color:#0000ff;">function</span> (data, textStatus){    <span style="color:#008000;">// data 可以是 xmlDoc, jsonObj, html, text, 等等.</span>    <span style="color:#008000;">//this; // 这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this</span>    <span style="color:#0000ff;">alert</span>(data.result);   }, "<span style="color:#8b0000;">json</span>");</pre>    <p>点击提交: </p>    <p>这里设置了请求的格式为"json": </p>    <p><a href="https://simg.open-open.com/show/43822f4e4daee4bb2465ce5cc6d30cce.png" rel="nofollow"><img alt="jQuery Ajax 全解析" src="https://simg.open-open.com/show/4f6c0835dfc4948544e863405756da6e.png" width="440" height="125" /></a> </p>    <p>如果你设置了请求的格式为"json",此时你没有设置Response回来的ContentType 为:Response.ContentType = "application/json"; 那么你将无法捕捉到返回的数据。 </p>    <p>注意一下,<span style="color:#0000ff;">alert</span>(data.result); 由于设置了Accept报头为“json”,这里返回的data就是一个对象,并不需要用eval()来转换为对象。 </p>    <p>  </p>    <p><span style="color:#bb0000;"><span style="font-size:medium;"><strong>4. jQuery.getScript</strong>( url, [callback] ) : 通过 GET 方式请求载入并执行一个 JavaScript 文件</span>。</span> </p>    <blockquote>     <h4>参数</h4>     <p><strong>url </strong>(String) : 待载入 JS 文件地址。 </p>     <p><strong>callback </strong>(Function) : (可选) 成功载入后回调函数。</p>    </blockquote>    <p>jQuery 1.2 版本之前,getScript 只能调用同域 JS 文件。 1.2中,您可以跨域调用 JavaScript 文件。注意:Safari 2 或更早的版本不能在全局作用域中同步执行脚本。如果通过 getScript 加入脚本,请加入延时函数。 </p>    <p>这个方法可以用在例如当只有编辑器focus()的时候才去加载编辑器需要的JS文件.下面看一些示例代码:</p> 加载并执行 test.js。    <p><strong>jQuery 代码:</strong> </p>    <p>$.getScript("test.js"); </p>    <p>加载并执行 AjaxEvent.js ,成功后显示信息。 </p>    <p><strong>jQuery 代码:</strong> </p>    <pre>$.getScript("<span style="color:#8b0000;">AjaxEvent.js</span>", <span style="color:#0000ff;">function</span>(){   <span style="color:#0000ff;">alert</span>("<span style="color:#8b0000;">AjaxEvent.js 加载完成并执行完成.你再点击上面的Get或Post按钮看看有什么不同?</span>"); });</pre>    <p>加载完后请重新点击一下上面的 Load 请求看看有什么不同。 </p>    <p><span style="color:#bb0000;font-size:medium;"><strong>jQuery Ajax 事件</strong></span> </p>    <p>Ajax请求会产生若干不同的事件,我们可以订阅这些事件并在其中处理我们的逻辑。在jQuery这里有两种Ajax事件:局部事件 和 全局事件。 </p>    <p><strong>局部事件</strong>就是在每次的Ajax请求时在方法内定义的,例如: </p>    <pre> $.ajax({    beforeSend: <span style="color:#0000ff;">function</span>(){      <span style="color:#008000;">// Handle the beforeSend event</span>    },    complete: <span style="color:#0000ff;">function</span>(){      <span style="color:#008000;">// Handle the complete event</span>    }    <span style="color:#008000;">// ...</span>  });</pre>    <p><strong>全局事件</strong>是每次的Ajax请求都会触发的,它会向DOM中的所有元素广播,在上面 getScript() 示例中加载的脚本就是全局Ajax事件。全局事件可以如下定义:</p>    <pre> $("<span style="color:#8b0000;">#loading</span>").bind("<span style="color:#8b0000;">ajaxSend</span>", <span style="color:#0000ff;">function</span>(){    $(<span style="color:#0000ff;">this</span>).show();  }).bind("<span style="color:#8b0000;">ajaxComplete</span>", <span style="color:#0000ff;">function</span>(){    $(<span style="color:#0000ff;">this</span>).hide();  });</pre>    <p>或者:</p>    <pre> $("<span style="color:#8b0000;">#loading</span>").ajaxStart(<span style="color:#0000ff;">function</span>(){    $(<span style="color:#0000ff;">this</span>).show();  }); </pre>    <p>我们可以在特定的请求将全局事件禁用,只要设置下 global 选项就可以了: </p>    <pre> $.ajax({    url: "<span style="color:#8b0000;">test.html</span>",    global: <span style="color:#0000ff;">false</span>,<span style="color:#008000;">// 禁用全局Ajax事件.</span>    <span style="color:#008000;">// ...</span>  });</pre>    <p>下面是jQuery官方给出的完整的Ajax事件列表: </p>    <div class="BlogContent TextContent">     <li><b>ajaxStart</b> (Global Event)<br /> This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.      <ul>       <li><b>beforeSend</b> (Local Event)<br /> This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be.) </li>       <li><b>ajaxSend</b> (Global Event)<br /> This global event is also triggered before the request is run. </li>       <li><b>success</b> (Local Event)<br /> This event is only called if the request was successful (no errors from the server, no errors with the data). </li>       <li><b>ajaxSuccess</b> (Global Event)<br /> This event is also only called if the request was successful. </li>       <li><b>error</b> (Local Event)<br /> This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request). </li>       <li><b>ajaxError</b> (Global Event)<br /> This global event behaves the same as the local error event. </li>       <li><b>complete</b> (Local Event)<br /> This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests. </li>       <li><b>ajaxComplete</b> (Global Event)<br /> This event behaves the same as the complete event and will be triggered every time an Ajax request finishes. </li>      </ul> </li>     <li><b>ajaxStop</b> (Global Event)<br /> This global event is triggered if there are no more Ajax requests being processed. <p>具体的全局事件请参考API文档。<br /> 好了,下面开始说jQuery里面功能最强的Ajax请求方法 $.ajax();   </p> <p>  </p> <p><span style="font-size:medium;"><span style="color:#bb0000;"><strong>jQuery.ajax</strong>( options ) : 通过 HTTP 请求加载远程数据</span></span> </p> <p>这个是jQuery 的底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。 </p> <p>$.ajax() 返回其创建的 XMLHttpRequest 对象。大多数情况下你无需直接操作该对象,但特殊情况下可用于手动终止请求。 </p> <p><strong>注意:</strong> 如果你指定了 dataType 选项,请确保服务器返回正确的 MIME 信息,(如 xml 返回 "text/xml")。错误的 MIME 类型可能导致不可预知的错误。见 <a href="/misc/goto?guid=4959500016617631457" rel="nofollow">Specifying the Data Type for AJAX Requests</a> 。<br /> 当设置 datatype 类型为 'script' 的时候,所有的远程(不在同一个域中)POST请求都回转换为GET方式。 </p> <p>$.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数信息。详细参数选项见下。 </p> <p>jQuery 1.2 中,您可以跨域加载 JSON 数据,使用时需将数据类型设置为 <a href="/misc/goto?guid=4959500016701261005" rel="nofollow">JSONP</a>。使用 <a href="/misc/goto?guid=4959500016701261005" rel="nofollow">JSONP</a> 形式调用函数时,如 "myurl?callback=?" jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。数据类型设置为 "jsonp" 时,jQuery 将自动调用回调函数。(这个我不是很懂) </p> <p>参数列表:</p>      <table border="1" cellspacing="2" cellpadding="2">       <tbody>        <tr>         <td><span style="color:#bb0000;">参数名</span></td>         <td><span style="color:#bb0000;">类型</span></td>         <td><span style="color:#bb0000;">描述</span></td>        </tr>        <tr>         <td><strong>url </strong></td>         <td>String</td>         <td>(默认: 当前页地址) 发送请求的地址。</td>        </tr>        <tr>         <td><strong>type</strong></td>         <td>String</td>         <td>(默认: "GET") 请求方式 ("POST" 或 "GET"), 默认为 "GET"。注意:其它 HTTP 请求方法,如 PUT 和 DELETE 也可以使用,但仅部分浏览器支持。</td>        </tr>        <tr>         <td><strong>timeout</strong></td>         <td>Number</td>         <td>设置请求超时时间(毫秒)。此设置将覆盖全局设置。</td>        </tr>        <tr>         <td><strong>async </strong></td>         <td>Boolean</td>         <td>(默认: true) 默认设置下,所有请求均为异步请求。如果需要发送同步请求,请将此选项设置为 false。注意,同步请求将锁住浏览器,用户其它操作必须等待请求完成才可以执行。</td>        </tr>        <tr>         <td><strong>beforeSend </strong></td>         <td>Function</td>         <td>发送请求前可修改 XMLHttpRequest 对象的函数,如添加自定义 HTTP 头。XMLHttpRequest 对象是唯一的参数。<br /> <pre><span style="color:#0000ff;">function</span> (XMLHttpRequest) {   <span style="color:#0000ff;">this</span>; <span style="color:#008000;">// the options for this ajax request</span> }</pre></td>        </tr>        <tr>         <td><strong>cache </strong></td>         <td>Boolean</td>         <td>(默认: true) jQuery 1.2 新功能,设置为 false 将不会从浏览器缓存中加载请求信息。</td>        </tr>        <tr>         <td><strong>complete </strong></td>         <td>Function</td>         <td>请求完成后回调函数 (请求成功或失败时均调用)。参数: XMLHttpRequest 对象,成功信息字符串。<br /> <pre><span style="color:#0000ff;">function</span> (XMLHttpRequest, textStatus) {   <span style="color:#0000ff;">this</span>; <span style="color:#008000;">// the options for this ajax request</span> }</pre></td>        </tr>        <tr>         <td><strong>contentType </strong></td>         <td>String</td>         <td>(默认: "application/x-www-form-urlencoded") 发送信息至服务器时内容编码类型。默认值适合大多数应用场合。</td>        </tr>        <tr>         <td><strong>data </strong></td>         <td>Object,<br /> String</td>         <td>发送到服务器的数据。将自动转换为请求字符串格式。GET 请求中将附加在 URL 后。查看 processData 选项说明以禁止此自动转换。必须为 Key/Value 格式。如果为数组,jQuery 将自动为不同值对应同一个名称。如 {foo:["bar1", "bar2"]} 转换为 '&foo=bar1&foo=bar2'。</td>        </tr>        <tr>         <td><strong>dataType </strong></td>         <td>String</td>         <td> <p>预期服务器返回的数据类型。如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息返回 responseXML 或 responseText,并作为回调函数参数传递,可用值: </p> <p>"xml": 返回 XML 文档,可用 jQuery 处理。 </p> <p>"html": 返回纯文本 HTML 信息;包含 script 元素。 </p> <p>"script": 返回纯文本 JavaScript 代码。不会自动缓存结果。 </p> <p>"json": 返回 JSON 数据 。 </p> <p>"jsonp": <a href="/misc/goto?guid=4959500016701261005" rel="nofollow">JSONP</a> 格式。使用 <a href="/misc/goto?guid=4959500016701261005" rel="nofollow">JSONP</a> 形式调用函数时,如 "myurl?callback=?" jQuery 将自动替换 ? 为正确的函数名,以执行回调函数。</p> </td>        </tr>        <tr>         <td><strong>error </strong></td>         <td>Function</td>         <td>(默认: 自动判断 (xml 或 html)) 请求失败时将调用此方法。这个方法有三个参数:XMLHttpRequest 对象,错误信息,(可能)捕获的错误对象。<br /> <pre><span style="color:#0000ff;">function</span> (XMLHttpRequest, textStatus, errorThrown) {   <span style="color:#008000;">// 通常情况下textStatus和errorThown只有其中一个有值 </span>   <span style="color:#0000ff;">this</span>; <span style="color:#008000;">// the options for this ajax request</span> }</pre></td>        </tr>        <tr>         <td><strong>global </strong></td>         <td>Boolean</td>         <td>(默认: true) 是否触发全局 AJAX 事件。设置为 false 将不会触发全局 AJAX 事件,如 ajaxStart 或 ajaxStop 。可用于控制不同的Ajax事件</td>        </tr>        <tr>         <td><strong>ifModified </strong></td>         <td>Boolean</td>         <td>(默认: false) 仅在服务器数据改变时获取新数据。使用 HTTP 包 Last-Modified 头信息判断。</td>        </tr>        <tr>         <td><strong>processData </strong></td>         <td>Boolean</td>         <td>(默认: true) 默认情况下,发送的数据将被转换为对象(技术上讲并非字符串) 以配合默认内容类型 "application/x-www-form-urlencoded"。如果要发送 DOM 树信息或其它不希望转换的信息,请设置为 false。</td>        </tr>        <tr>         <td><strong>success </strong></td>         <td>Function</td>         <td>请求成功后回调函数。这个方法有两个参数:服务器返回数据,返回状态<br /> <pre><span style="color:#0000ff;">function</span> (data, textStatus) {   <span style="color:#008000;">// data could be xmlDoc, jsonObj, html, text, etc...</span>   <span style="color:#0000ff;">this</span>; <span style="color:#008000;">// the options for this ajax request</span> }</pre></td>        </tr>       </tbody>      </table> <p>这里有几个Ajax事件参数:<strong>beforeSend </strong>,<strong>success </strong>,<strong>complete ,error 。</strong>我们可以定义这些事件来很好的处理我们的每一次的Ajax请求。注意一下,这些Ajax事件里面的 <span style="color:#0000ff;">this</span> 都是指向Ajax请求的选项信息的(请参考说 get() 方法时的this的图片)。<br /> 请认真阅读上面的参数列表,如果你要用jQuery来进行Ajax开发,那么这些参数你都必需熟知的。 </p> <h4>示例代码,获取博客园首页的文章题目:</h4> <pre>$.ajax({   type: "<span style="color:#8b0000;">get</span>",   url: "<span style="color:#8b0000;">http://www.cnblogs.com/rss</span>",   beforeSend: <span style="color:#0000ff;">function</span>(XMLHttpRequest){    <span style="color:#008000;">//ShowLoading();</span>   },   success: <span style="color:#0000ff;">function</span>(data, textStatus){    $("<span style="color:#8b0000;">.ajax.ajaxResult</span>").html("");    $("<span style="color:#8b0000;">item</span>",data).each(<span style="color:#0000ff;">function</span>(i, domEle){     $("<span style="color:#8b0000;">.ajax.ajaxResult</span>").append("<span style="color:#8b0000;"><li>"+$(domEle).children("<span style="color:#8b0000;">title</span>").text()+"");    });   },   complete: <span style="color:#0000ff;">function</span>(XMLHttpRequest, textStatus){    <span style="color:#008000;">//HideLoading();</span>   },   error: <span style="color:#0000ff;">function</span>(){    <span style="color:#008000;">//请求出错处理</span>   } });</li> </span></pre> <p>这里将显示首页文章列表。</p> <p> </p> <p> </p> <p><span style="color:#bb0000;font-size:medium;"><strong>其他</strong></span> </p> <p><span style="color:#bb0000;"><strong>jQuery.ajaxSetup</strong>( options ) : 设置全局 AJAX 默认选项。</span></p> <p>设置 AJAX 请求默认地址为 "/xmlhttp/",禁止触发全局 AJAX 事件,用 POST 代替默认 GET 方法。其后的 AJAX 请求不再设置任何选项参数。 </p> <p><strong>jQuery 代码:</strong> </p> <pre>$.ajaxSetup({   url: "<span style="color:#8b0000;">/xmlhttp/</span>",   global: <span style="color:#0000ff;">false</span>,   type: "<span style="color:#8b0000;">POST</span>" }); $.ajax({ data: myData });</pre> <p> </p> <p><strong><span style="color:#bb0000;font-size:medium;">serialize() 与 serializeArray()</span></strong></p> <p>serialize() : 序列表表格内容为字符串。</p> <p>serializeArray() : 序列化表格元素 (类似 '.serialize()' 方法) 返回 JSON 数据结构数据。 </p> <p>示例:</p> <p>HTML代码:</p> <pre><span style="color:#0000ff;"><</span><span style="color:#800000;">p</span> <span style="color:#ff0000;">id</span>=<span style="color:#0000ff;">"results"</span><span style="color:#0000ff;">></span><span style="color:#0000ff;"><</span><span style="color:#800000;">b</span><span style="color:#0000ff;">></span>Results: <span style="color:#0000ff;">                                   <!--</span--><span style="color:#800000;">b</span><span style="color:#0000ff;">></span> <span style="color:#0000ff;">                                        <!--</span--><span style="color:#800000;">p</span><span style="color:#0000ff;">></span> <span style="color:#0000ff;"><</span><span style="color:#800000;">form</span><span style="color:#0000ff;">></span>   <span style="color:#0000ff;"><</span><span style="color:#800000;">select</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"single"</span><span style="color:#0000ff;">></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>Single<span style="color:#0000ff;">                                             <!--</span--><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>Single2<span style="color:#0000ff;">                                                  <!--</span--><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>   <span style="color:#0000ff;">                                                       <!--</span--><span style="color:#800000;">select</span><span style="color:#0000ff;">></span>   <span style="color:#0000ff;"><</span><span style="color:#800000;">select</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"multiple"</span> <span style="color:#ff0000;">multiple</span>=<span style="color:#0000ff;">"multiple"</span><span style="color:#0000ff;">></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">option</span> <span style="color:#ff0000;">selected</span>=<span style="color:#0000ff;">"selected"</span><span style="color:#0000ff;">></span>Multiple<span style="color:#0000ff;">                                                            <!--</span--><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>Multiple2<span style="color:#0000ff;">                                                                 <!--</span--><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>     <span style="color:#0000ff;"><</span><span style="color:#800000;">option</span> <span style="color:#ff0000;">selected</span>=<span style="color:#0000ff;">"selected"</span><span style="color:#0000ff;">></span>Multiple3<span style="color:#0000ff;">                                                                      <!--</span--><span style="color:#800000;">option</span><span style="color:#0000ff;">></span>   <span style="color:#0000ff;">                                                                           <!--</span--><span style="color:#800000;">select</span><span style="color:#0000ff;">></span><span style="color:#0000ff;"><</span><span style="color:#800000;">br</span><span style="color:#0000ff;">/></span>   <span style="color:#0000ff;"><</span><span style="color:#800000;">input</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">"checkbox"</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"check"</span> <span style="color:#ff0000;">value</span>=<span style="color:#0000ff;">"check1"</span><span style="color:#0000ff;">/></span> check1   <span style="color:#0000ff;"><</span><span style="color:#800000;">input</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">"checkbox"</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"check"</span> <span style="color:#ff0000;">value</span>=<span style="color:#0000ff;">"check2"</span> <span style="color:#ff0000;">checked</span>=<span style="color:#0000ff;">"checked"</span><span style="color:#0000ff;">/></span> check2   <span style="color:#0000ff;"><</span><span style="color:#800000;">input</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">"radio"</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"radio"</span> <span style="color:#ff0000;">value</span>=<span style="color:#0000ff;">"radio1"</span> <span style="color:#ff0000;">checked</span>=<span style="color:#0000ff;">"checked"</span><span style="color:#0000ff;">/></span> radio1   <span style="color:#0000ff;"><</span><span style="color:#800000;">input</span> <span style="color:#ff0000;">type</span>=<span style="color:#0000ff;">"radio"</span> <span style="color:#ff0000;">name</span>=<span style="color:#0000ff;">"radio"</span> <span style="color:#ff0000;">value</span>=<span style="color:#0000ff;">"radio2"</span><span style="color:#0000ff;">/></span> radio2<span style="color:#0000ff;">                                                                                <!--</span--><span style="color:#800000;">form</span><span style="color:#0000ff;">></span> </span></span></span></span></span></span></span></span></span></span></pre> <p><a href="https://simg.open-open.com/show/008efb991d06cad8374198a9f1cbaac8.png" rel="nofollow"><img alt="jQuery Ajax 全解析" src="https://simg.open-open.com/show/5d1b536ba8a390b99786718245cd9f40.png" width="812" height="106" /></a> </p> <p><strong><span style="color:#bb0000;">serializeArray() 结果为:</span></strong> </p> <p><a href="https://simg.open-open.com/show/7f8f86032555dffb6b4cc372ada22394.png" rel="nofollow"><img alt="jQuery Ajax 全解析" src="https://simg.open-open.com/show/05c0e5a1d84ff12d35cbb075084dec92.png" width="513" height="338" /></a> </p> <p>  </p> <p><strong><span style="color:#bb0000;">一些资源</span></strong></p> <p>一个收集jQuery插件的列表:<a href="http://www.open-open.com/ajax/jquery.htm " target="_blank">http://www.open-open.com/ajax/jquery.htm </a></p> <p></p> </li>    </div>