-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-ajax.code-snippets
33 lines (33 loc) · 1.52 KB
/
jquery-ajax.code-snippets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{
"Print to console": {
// "scope": "javascript,typescript,php,java,css,html",
"prefix": "ajax",
"body": [
"\\$.ajax({",
" url: \"请求地址\", // 必填,请求的地址",
" type: \"请求方式\", // 选填,请求方式,默认是 GET(忽略大小写)",
" data: {}, // 选填,发送请求是携带的参数",
" dataType: \"json\", // 选填,期望返回值的数据类型,默认是 string",
" async: true, // 选填,是否异步,默认是 true",
" headers: {",
" 'Content-Type': 'application/json'",
" }, // 获知请求中的消息主体是用何种方式编码",
" success:function(res){",
" //将json对象转为字符串:",
" JSON.stringify(obj);",
" //将字符串转为json对象:",
" JSON.parse(string);",
" }, // 选填,成功的回调函数",
" error () {}, // 选填,失败的回调函数,参数有xhr,是ajax对象,status状态,err错误信息",
" cache: true, // 选填,是否缓存,默认是 true",
" timeout: 1000, // 选填,超时时间,单位毫秒",
" context: div, // 选填,回调函数中的 this 指向,默认是 ajax 对象",
" beforeSend: function () {",
" // 禁用按钮防止重复提交,防止重复数据",
" $(\"#submit\").attr({ disabled: \"disabled\" });",
" },",
"})"
],
"description": "jquery的ajax请求"
}
}