傳統ajaxios
$.ajax({ type: "GET", url: "test.json", data: {username:$("#username").val(), content:$("#content").val()}, dataType: "json", success: function(data){ console.log(data); } });
使用fetchgit
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兼容使用:可使用github
whatwg-fetch
參考:https://github.com/github/fetchajax
可是IOS7不支持Promise,致使,一直報錯,Can't find variable: Promise ,ios8及以上支持Promisejson
決解辦法:http://stackoverflow.com/questions/22462396/cant-find-variable-promise-on-safari/22463561
使用promise
Ember.RSVP.Promise
而這樣就失去了方便簡潔優雅的目的,只能等ios7慢慢被淘汰再用。。。。fetch