首页 > 移动平台 > 详细

移动端使用fetch

时间:2016-10-21 11:18:37      阅读:462      评论:0      收藏:0      [点我收藏+]

传统ajax

$.ajax({
             type: "GET",
             url: "test.json",
             data: {username:$("#username").val(), content:$("#content").val()},
             dataType: "json",
             success: function(data){
                         console.log(data);
                      }
         });

 

使用fetch

fetch(‘/list/column‘)
            .then((response) => {
                return response.json();
            })
            .then((data) => {
                console.log(data);
                this.setState({
                    data: JSON.stringify(data)
                });
                // console.log(this.state.data);
            })
            .catch((ex) => {
                console.log(ex);
            });

 

 

 

fetch兼容使用:可以使用

whatwg-fetch

参考:https://github.com/github/fetch

但是IOS7不支持Promise,导致,一直报错,Can‘t find variable: Promise ,ios8及以上支持Promise
技术分享

 


决解办法:http://stackoverflow.com/questions/22462396/cant-find-variable-promise-on-safari/22463561
使用

Ember.RSVP.Promise

而这样就失去了方便简洁优雅的目的,只能等ios7慢慢被淘汰再用。。。。

示例代码地址: https://github.com/fengnovo/diary/tree/master/react/20161021/webpack-dev-server-proxy-test

移动端使用fetch

原文:http://www.cnblogs.com/fengnovo/p/5983597.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!