mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-03-29 17:58:42 +00:00
54 lines
1.3 KiB
HTML
54 lines
1.3 KiB
HTML
<script>
|
|
var query = `
|
|
query ($id: Int) { # Define which variables will be used in the query (id)
|
|
Media (id: $id, type: ANIME) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
|
|
id
|
|
title {
|
|
romaji
|
|
english
|
|
native
|
|
}
|
|
}
|
|
}
|
|
`;
|
|
|
|
// Define our query variables and values that will be used in the query request
|
|
var variables = {
|
|
id: 16498
|
|
};
|
|
|
|
// Define the config we'll need for our Api request
|
|
var url = 'https://graphql.anilist.co',
|
|
options = {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
query: query,
|
|
variables: variables
|
|
})
|
|
};
|
|
|
|
// Make the HTTP Api request
|
|
fetch(url, options).then(handleResponse)
|
|
.then(handleData)
|
|
.catch(handleError);
|
|
|
|
function handleResponse(response) {
|
|
return response.json().then(function(json) {
|
|
return response.ok ? json : Promise.reject(json);
|
|
});
|
|
}
|
|
|
|
function handleData(data) {
|
|
console.log(data);
|
|
}
|
|
|
|
function handleError(error) {
|
|
alert('Error, check console');
|
|
console.error(error);
|
|
}
|
|
|
|
</script>
|