Client - 用Fetch跟Server要資料
方法種類:
- 1.XMLHttpRequest (一般browser內建)
- 2.使用jQuery的
$.get()
,$.ajax()
. (其也是封裝使用了XMLHttpRequest). - 3.
如果要在全部的Browser上面使用Fetch, 可使用
以下是使用fetch的example, 取得github上任意帳號的資料,
fetch('https://api.github.com/users/任意帳號')
.then(function(res) {
return res.json();
}).then(function(json){
console.log(json);
});
Last modified 5yr ago