Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 12 links for fetch returning errors #40

Open
Mishelbi opened this issue Dec 24, 2018 · 3 comments
Open

Chapter 12 links for fetch returning errors #40

Mishelbi opened this issue Dec 24, 2018 · 3 comments
Assignees

Comments

@Mishelbi
Copy link

When trying to do the example on pages 523-527, click either the numbers or chuck buttons and an error is returned: net::ERR_CONNECTION_RESET. Is there updated URLs or code?

@Mishelbi
Copy link
Author

https://api.chucknorris.io/jokes/random works for chuck norris but I can't find one for numbers

@simonmackie
Copy link

Paging @daz4126

@daz4126
Copy link
Collaborator

daz4126 commented Jan 20, 2019

Hi @Mishelbi. Sorry for the delay in replying - work has been busy and I haven't done much JS programming recently. I had a look at this and it worked for me. This is my code for the text button:

textButton.addEventListener('click', function() {
fetch(textURL)
.then( function(response) {
 outputDiv.innerHTML = 'Waiting for response...';
 if(response.ok) {
   return response;
 }
 throw Error(response.statusText);
})
.then( response => response.text() )
.then( text => outputDiv.innerText = text )
.catch( error => console.log('There was an error:', error))
},false);

Can you try using that and see if it now works?

Hope that helps - let me know how you get on.

Daz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants