# Client - 用Fetch跟Server要資料

方法種類:

1. XMLHttpRequest (一般browser內建)
2. 使用jQuery的`$.get()`, `$.ajax()`. (其也是封裝使用了XMLHttpRequest).
3. 使用Node.js或部份Browser內建的Fetch, e.g. <https://github.com/bitinn/node-fetch>

如果要在全部的Browser上面使用Fetch, 可使用

1. Bower <https://github.com/github/fetch>), or
2. CDN \[<https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js>] (<https://cdnjs.cloudflare.com/ajax/libs/fetch/1.0.0/fetch.min.js>), 其介紹:<https://cdnjs.com/libraries/fetch> 來安裝.

以下是使用fetch的example, 取得github上任意帳號的資料，

```javascript
fetch('https://api.github.com/users/任意帳號')
.then(function(res) {
  return res.json();
}).then(function(json){
  console.log(json);
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lifeoverflow.gitbook.io/learning-javascript/shi-ji-ying-yong/client-yong-fetch-gen-server-yao-zi-liao.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
