JQuery中$.ajax()方法参数详解
来源:互联网 发布:傅园慧网络直播 编辑:程序博客网 时间:2024/05/02 01:07
JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址。
type: 要求为String类型的参数,请求方式(post或get)默认为get。注意其他http请求方法,例如put和
timeout: 要求为Number类型的参数,设置请求超时时间(毫秒)。此设置将覆盖$.ajaxSetup()方法的全局设
async:要求为Boolean类型的参数,默认设置为true,所有请求均为异步请求。
cache:要求为Boolean类型的参数,默认为true(当dataType为script时,默认为false)。
data: 要求为Object或String类型的参数,发送到服务器的数据。如果已经不是字符串,将自动转换为字符串格
dataType: 要求为String类型的参数,预期服务器返回的数据类型。如果不指定,JQuery将自动根据http包mime
beforeSend:要求为Function类型的参数,发送请求前可以修改XMLHttpRequest对象的函数,例如添加自定义
complete:要求为Function类型的参数,请求完成后调用的回调函数(请求成功或失败时均调用)。
success:要求为Function类型的参数,请求成功后调用的回调函数,有两个参数。
error:要求为Function类型的参数,请求失败时被调用的函数。该函数有3个参数,即XMLHttpRequest对象、错
contentType:要求为String类型的参数,当发送信息至服务器时,内容编码类型默认
dataFilter:要求为Function类型的参数,给Ajax返回的原始数据进行预处理的函数。
global:要求为Boolean类型的参数,默认为true。表示是否触发全局ajax事件。设置为false将不会触发全局
ifModified:要求为Boolean类型的参数,默认为false。仅在服务器数据改变时获取新数据。
jsonp:要求为String类型的参数,在一个jsonp请求中重写回调函数的名字。
username:要求为String类型的参数,用于响应HTTP访问认证请求的用户名。
password:要求为String类型的参数,用于响应HTTP访问认证请求的密码。
processData:要求为Boolean类型的参数,默认为true。默认情况下,发送的数据将被转换为对象(从技术角度
scriptCharset:要求为String类型的参数,只有当请求时dataType为"jsonp"或者"script",并且type是GET时
实例代码:
<span style="font-size:14px;">$(function(){$('#send').click(function(){ $.ajax({ type: "GET", url: "test.json", data: {username:$("#username").val(), content:$("#content").val()}, dataType: "json", success: function(data){ $('#resText').empty(); //清空resText里面的所有内容 var html = ''; $.each(data, function(commentIndex, comment){ html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para"' + comment['content'] + '</p></div>'; }); $('#resText').html(html); }</span> }); });});
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- JQuery中$.ajax()方法参数详解
- docker源码阅读
- hdoj-1233-还是畅通工程
- 英语笔试题1
- malloc内存分配
- swift 笔记
- JQuery中$.ajax()方法参数详解
- 访客模式(Guest Mode)
- 谈.Net委托与线程——创建无阻塞的异步调用(一)
- java中==与equals的区别
- vs2013在C++中调用Lua
- 谈.Net委托与线程——创建无阻塞的异步调用(二)
- 猎杀乌姆帕斯
- ICCv13,parts
- 题目1464