cnblogs/dcrenl/JQuery中$.ajax()方法参数详解(1).html
2024-09-24 12:43:01 +08:00

223 lines
42 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<div id="sina_keyword_ad_area2" class="articalContent newfont_family">
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
url: 要求为String类型的参数默认为当前页地址发送请求的地址。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
type: 要求为String类型的参数请求方式post或get默认为get。注意其他http请求方法例如put和</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>delete也可以使用但仅部分浏览器支持。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
timeout: 要求为Number类型的参数设置请求超时时间毫秒。此设置将覆盖$.ajaxSetup()方法的全局设</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>置。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
async要求为Boolean类型的参数默认设置为true所有请求均为异步请求。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>如果需要发送同步请求请将此选项设置为false。注意同步请求将锁住浏览器用户其他操作必须等</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>待请求完成才可以执行。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
cache要求为Boolean类型的参数默认为true当dataType为script时默认为false</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>设置为false将不会从浏览器缓存中加载请求信息。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
data: 要求为Object或String类型的参数发送到服务器的数据。如果已经不是字符串将自动转换为字符串格</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>式。get请求中将附加在url后。防止这种自动转换可以查看processData选项。对象必须为key/value格</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>式,例如{foo1:"bar1",foo2:"bar2"}转换为&amp;foo1=bar1&amp;foo2=bar2。如果是数组JQuery将自动为不同</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>值对应同一个名称。例如{foo:["bar1","bar2"]}转换为&amp;foo=bar1&amp;foo=bar2。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
dataType:
要求为String类型的参数预期服务器返回的数据类型。如果不指定JQuery将自动根据http包mime</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>信息返回responseXML或responseText并作为回调函数参数传递。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>可用的类型如下:</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>xml返回XML文档可用JQuery处理。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>html返回纯文本HTML信息包含的script标签会在插入DOM时执行。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>script返回纯文本JavaScript代码。不会自动缓存结果。除非设置了cache参数。注意在远程请求</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>不在同一个域下所有post请求都将转为get请求。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>json返回JSON数据。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>jsonpJSONP格式。使用SONP形式调用函数时例如myurl?callback=?JQuery将自动替换后一个</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>“?”为正确的函数名,以执行回调函数。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>text返回纯文本字符串。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
beforeSend要求为Function类型的参数发送请求前可以修改XMLHttpRequest对象的函数例如添加自定义</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>HTTP头。在beforeSend中如果返回false可以取消本次ajax请求。XMLHttpRequest对象是惟一的参</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>数。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>function(XMLHttpRequest){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />this;&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//调用本次ajax请求时传递的options参数</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>}</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
complete要求为Function类型的参数请求完成后调用的回调函数请求成功或失败时均调用</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>参数XMLHttpRequest对象和一个描述成功请求类型的字符串。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>function(XMLHttpRequest,
textStatus){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>this;&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//调用本次ajax请求时传递的options参数</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>}</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
success要求为Function类型的参数请求成功后调用的回调函数有两个参数。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>(1)由服务器返回并根据dataType参数进行处理后的数据。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>(2)描述状态的字符串。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>function(data,
textStatus){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />//data可能是xmlDoc、jsonObj、html、text等等</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>this;&nbsp;<wbr><wbr />&nbsp;<wbr>//调用本次ajax请求时传递的options参数</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
error要求为Function类型的参数请求失败时被调用的函数。该函数有3个参数即XMLHttpRequest对象、错</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>误信息、捕获的错误对象(可选)。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>ajax事件函数如下</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>function(XMLHttpRequest,
textStatus, errorThrown){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//通常情况下textStatus和errorThrown只有其中一个包含信息</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>this;&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//调用本次ajax请求时传递的options参数</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>}</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
contentType要求为String类型的参数当发送信息至服务器时内容编码类型默认</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>为"application/x-www-form-urlencoded"。该默认值适合大多数应用场合。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
dataFilter要求为Function类型的参数给Ajax返回的原始数据进行预处理的函数。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>提供data和type两个参数。data是Ajax返回的原始数据type是调用jQuery.ajax时提供的</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>dataType参数。函数返回的值将由jQuery进一步处理。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>function(data,
type){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//返回处理后的数据</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>return
data;</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>}</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
global要求为Boolean类型的参数默认为true。表示是否触发全局ajax事件。设置为false将不会触发全局</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>ajax事件ajaxStart或ajaxStop可用于控制各种ajax事件。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
ifModified要求为Boolean类型的参数默认为false。仅在服务器数据改变时获取新数据。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>服务器数据改变判断的依据是Last-Modified头信息。默认值是false即忽略头信息。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
jsonp要求为String类型的参数在一个jsonp请求中重写回调函数的名字。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>该值用来替代在"callback=?"这种GET或POST请求中URL参数里的"callback"部分,例如</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>{jsonp:'onJsonPLoad'}会导致将"onJsonPLoad=?"传给服务器。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
username要求为String类型的参数用于响应HTTP访问认证请求的用户名。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
password要求为String类型的参数用于响应HTTP访问认证请求的密码。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
processData要求为Boolean类型的参数默认为true。默认情况下发送的数据将被转换为对象从技术角度</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>来讲并非字符串)以配合默认内容类型"application/x-www-form-urlencoded"。如果要发送DOM</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>树信息或者其他不希望转换的信息请设置为false。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
scriptCharset要求为String类型的参数只有当请求时dataType为"jsonp"或者"script"并且type是GET时</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>才会用于强制修改字符集(charset)。通常在本地和远程的内容编码不同时使用。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr /></P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
案例代码:</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
$(function(){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>$('#send').click(function(){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>$.ajax({</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>type:
"GET",</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>url:
"test.json",</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>data:
{username:$("#username").val(), content:$("#content").val()},</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>dataType:
"json",</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />success:
function(data){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />$('#resText').empty();&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>//清空resText里面的所有内容</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>var
html = '';&nbsp;<wbr><wbr /></P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>$.each(data,
function(commentIndex,&nbsp;<wbr><font COLOR="#FF0000" STYLE="word-wrap: normal; word-break: normal;">comment</FONT>){</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>html
+= '</P>
<div>
<h6>' +&nbsp;<wbr><font COLOR="#FF0000" STYLE="word-wrap: normal; word-break: normal;">comment</FONT>['<font COLOR="#1704FE" STYLE="word-wrap: normal; word-break: normal;">username</FONT>']<br />
<br /></H6>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>+
':</P>
<p><font COLOR="#FF0000" STYLE="word-wrap: normal; word-break: normal;">comment</FONT>['<font COLOR="#1704FE" STYLE="word-wrap: normal; word-break: normal;">content</FONT>']</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>+
'</P>
</DIV>
';
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>});</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>$('#resText').html(html);</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>}</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>});</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr><wbr />&nbsp;<wbr>});</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
});</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
&nbsp;<wbr><wbr /></P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
顺便说一下$.each()函数:</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
$.each()函数不同于JQuery对象的each()方法它是一个全局函数不操作JQuery对象而是以一个数组或者对象作为第1个参数以一个回调函数作为第2个参数。回调函数拥有两个参数第1个为对象的成员或数组的索引第2个为对应变量或内容。</P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
<br /></P>
<p STYLE="margin: 0px 0px 5px; padding: 0px; border: 0px; list-style: none; word-wrap: normal; word-break: normal; color: rgb(70, 70, 70); font-family: simsun; background-color: rgb(220, 220, 220);">
转自http://blog.sina.com.cn/s/blog_4f925fc30100la36.html</P>
</div>