reqwest请求api和约束(转载)
转自:https://www.oschina.net/p/reqwest
reqwest 用于浏览器异步HTTP请求。支持xmlHttpRequest, JSONP, CORS, 和 CommonJS约束。
API
|
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
reqwest('path/to/html', function (resp) { qwery('#content').html(resp)})reqwest({ url: 'path/to/html' , method: 'post' , data: { foo: 'bar', baz: 100 } , success: function (resp) { qwery('#content').html(resp) }})reqwest({ url: 'path/to/html' , method: 'get' , data: [ { name: 'foo', value: 'bar' }, { name: 'baz', value: 100 } ] , success: function (resp) { qwery('#content').html(resp) }})reqwest({ url: 'path/to/json' , type: 'json' , method: 'post' , error: function (err) { } , success: function (resp) { qwery('#content').html(resp.content) }})reqwest({ url: 'path/to/json' , type: 'json' , method: 'post' , contentType: 'application/json' , headers: { 'X-My-Custom-Header': 'SomethingImportant' } , error: function (err) { } , success: function (resp) { qwery('#content').html(resp.content) }})// Uses XMLHttpRequest2 credentialled requests (cookies, HTTP basic auth) if supportedreqwest({ url: 'path/to/json' , type: 'json' , method: 'post' , contentType: 'application/json' , crossOrigin: true , withCredentials: true , error: function (err) { } , success: function (resp) { qwery('#content').html(resp.content) }})reqwest({ url: 'path/to/data.jsonp?callback=?' , type: 'jsonp' , success: function (resp) { qwery('#content').html(resp.content) }})reqwest({ url: 'path/to/data.jsonp?foo=bar' , type: 'jsonp' , jsonpCallback: 'foo' , jsonpCallbackName: 'bar' , success: function (resp) { qwery('#content').html(resp.content) }})reqwest({ url: 'path/to/data.jsonp?foo=bar' , type: 'jsonp' , jsonpCallback: 'foo' , success: function (resp) { qwery('#content').html(resp.content) } , complete: function (resp) { qwery('#hide-this').hide() }}) |
约束
|
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
34
35
36
37
38
39
40
41
42
43
44
45
|
reqwest({ url: 'path/to/data.jsonp?foo=bar' , type: 'jsonp' , jsonpCallback: 'foo'}) .then(function (resp) { qwery('#content').html(resp.content) }, function (err, msg) { qwery('#errors').html(msg) }) .always(function (resp) { qwery('#hide-this').hide() })reqwest({ url: 'path/to/data.jsonp?foo=bar' , type: 'jsonp' , jsonpCallback: 'foo'}) .then(function (resp) { qwery('#content').html(resp.content) }) .fail(function (err, msg) { qwery('#errors').html(msg) }) .always(function (resp) { qwery('#hide-this').hide() })var r = reqwest({ url: 'path/to/data.jsonp?foo=bar' , type: 'jsonp' , jsonpCallback: 'foo' , success: function () { setTimeout(function () { r .then(function (resp) { qwery('#content').html(resp.content) }, function (err) { }) .always(function (resp) { qwery('#hide-this').hide() }) }, 15) }}) |
支持的浏览器
IE6+
Chrome 1+
Safari 3+
Firefox 1+
Opera
reqwest请求api和约束(转载)的更多相关文章
- [HTTP那些事]网络请求API
在Android上,原生API有两个,HttpUrlConnection和HttpClient,它们对封装Socket进行封装,让HTTP请求变得简单.这应该也算框架吧? 想象下,如果没有HttpUr ...
- 小程序前端防止重复点击请求api的简陋方法
upload: function () { let that = this; let {uploadFlag} = that.data; if (that.data.uploadFlag) { ret ...
- 关于ajax跨域请求API数据的一些问题
一般来说我们使用jquery的ajax来跨域请求API数据的时候每次请求,就只能请求一组数据,而且当我们再次点击发送ajax请求的时候,新请求的数据会覆盖掉原来的数据,那么如何每次在请求的数据的时候, ...
- 在线HTTP POST/GET模拟请求api接口http请求测试工具https://post.jsonin.com/
在线HTTP POST/GET模拟请求api接口http请求测试工具 在线POST/GET接口测试工具https://post.jsonin.com/ Json在线解析及格式化校验工具 https:/ ...
- ASP.NET Web Api 安全性(转载)
转载地址:http://www.cnblogs.com/fzrain/p/3552423.html 在Web Api中强制使用Https 我们可以在IIS级别配置整个Web Api来强制使用Https ...
- HTML5 Geolocation API工作原理[转载]
大家都知道,HTML5 Geolocation 可以使用 IP 地址.基于 Web 的数据库.无线网络连接和三角测量或 GPS 技术来确定经度和纬度. 问题: 在一个基于地理位置服务的个人业余项目(小 ...
- 跨域请求——WebClient通过get和post请求api
AJAX不可以实现跨域请求,经过特殊处理才行.一般后台可以通过WebClient实现跨域请求~ //get 请求 string url = string.Format("htt ...
- 微信小程序开发—快速掌握组件及API的方法---转载
微信小程序框架为开发者提供了一系列的组件和API接口. 组件主要完成小程序的视图部分,例如文字.图片显示.API主要完成逻辑功能,例如网络请求.数据存储.音视频播放控制,以及微信开放的微信登录.微信支 ...
- 第三篇、微信小程序-网络请求API
wx.request(OBJECT)发起的是https请求.一个微信小程序,同时只能有5个网络请求连接. OBJECT参数说明: 效果图: net.js Page({ data:{ result:{} ...
随机推荐
- CSS、HTML5、JS
[att*=value]{}包含value属性的所有元素样式.[id*=div]{} a[href$=jpg]:after{} [att^=value]{}开头字符包含value属性的所有元素样式 [ ...
- Redmine性能测试
Redmine部署使用有一个月了,反馈有时很慢. 1.查看log发现,事务更新后要发送Email,如果连接邮件服务器有问题,会等待超时,导致很慢. 2.解决发送邮件问题后,仍然有时慢,ActiveRe ...
- maven生命周期和插件
maven生命周期和插件 生命周期 maven的生命周期有三套,互相独立.每个生命周期含有不同阶段,常用如下 clean 清理项目 pre-clean 执行清理前需要完成的工作 clean 清理上一次 ...
- 【转】解决eclipse新导入工程无法run as server
转载地址:http://blog.csdn.net/huang86411/article/details/12118309 问题描述: 从SVN或者别处搞过来的web项目,利用eclipse工具,新建 ...
- git的一些命令行
以下代码均在命令行中执行:在目标文件夹目录下: 1.初始化一个Git仓库,使用git init命令. 2.添加文件到Git仓库,分两步: 第一步,使用命令git add <file>,注意 ...
- java中filter的用法 内部资料 请勿转载 谢谢合作
filter过滤器主要使用于前台向后台传递数据是的过滤操作.程度很简单就不说明了,直接给几个已经写好的代码: 一.使浏览器不缓存页面的过滤器 Java代码 import javax.servlet ...
- jmx配置
# ----- Execute The Requested Command ----------------------------------------- # ----- JMX Config S ...
- Git使用教程【转】
Git使用教程 一:Git是什么? Git是目前世界上最先进的分布式版本控制系统. 二:SVN与Git的最主要的区别? SVN是集中式版本控制系统,版本库是集中放在中央服务器的,而干活的时候,用的都是 ...
- Hibernate之全面认识
Hibernate体系架构 Hibernate通过配置文件管理底层的JDBC连接,将用户从原始的JDBC释放出来,使得用户无需再关注底层的JDBC操作,而是以面向对象的方式进行持久化操作.这种全面的解 ...
- Ubuntu 16.04 LTS 安装 Nginx/PHP 5.6/MySQL 5.7 (LNMP) 与Laravel
Ubuntu 16.04 LTS 安装 Nginx/PHP 5.6/MySQL 5.7 (LNMP) 与Laravel 1.MySQL安装[安装 MariaDB]MariaDB是MySQL的一个分支首 ...