Ars*_*-II 3 javascript graphql
例如,我如何使用XMLHttpRequest? 查询和 serverUrl 如下:
const serverUrl = 'http://example.com/graphql/'
const query = {
query: `{
viewer {
date
}
}`
};
Run Code Online (Sandbox Code Playgroud)
POST请求与'Content-Type', 'application/json'const yourServerUrl = 'http://example.com/graphql'
const yourQuery = {
query: `{
users {
firstName
}
}`
};
// below ordinary XHR request with console.log
const xhr = new XMLHttpRequest();
xhr.responseType = 'json';
xhr.open('POST', yourServerUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onload = function () {
console.log('data returned:', xhr.response);
};
xhr.send(JSON.stringify(yourQuery));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2416 次 |
| 最近记录: |