I
I
Ingerniated2017-04-02 17:21:02
JSON
Ingerniated, 2017-04-02 17:21:02

Why is fetch not output?

Why does he not want to give out the contents of the file, but also does not write an error?
The syntax of the fetch method is:
let promise = fetch(url[, options]);
url is the URL to make a request to,
options is an optional object with request settings.
<button class="redStream">Make</button>

let fet = fetch('info.json').then(function(response) {
  return response.json();
}).catch(alert);

var rs = document.querySelector(".redStream");
rs.addEventListener("click", fet);

// info.json
{
"data0": "<h1>hello</h1>",
"data1":"<h1>world</h1>",
"data2":"<h1>hello wordls</h1>"
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Yarkov, 2017-04-02
@Ingernirated

Why does he not want to give out the contents of the file

Where to issue it? The request worked, no error was thrown. You don't output the result.
https://jsfiddle.net/yarkov_aleksei/7L21gL5x/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question