0

I am unable to request JSON from HTML using request.

I am using the request package from npm.

<!DOCTYPE html>
<html lang="en">
  <head>
    <title>MySite!</title>
  </head>
  <body>
      <h2>
        its ya boi 
      </h2>
      <button onclick=ree>workkkkk</button>
      <script>
    const request = require('request')
    function ree() {
    request('https://api-quiz.hype.space/shows/now',(error,response,body) => { //requests data from the hq trivia api
    //bodys = JSON.parse(body)
    //document.getElementById("para").innerHTML = (bodys.nextShowPrize)
    //console.log(`Next game: ${body.nextShowTime}`)
    alert(body)
    })}
      </script>
  </body>
</html>
1
  • 2
    In what way is this code failing? Are you getting an error? An unexpected result? Something else? Is there anything on the browser's development console? In the browser's debugging tools, is the AJAX request made? What is the server's response? When you step through in the browser's script debugger, what happens? Commented May 19, 2019 at 21:02

1 Answer 1

1

You could use fetch.

fetch('https://api-quiz.hype.space/shows/now')
  .then(res => res.json())
  .then(console.log)

Sign up to request clarification or add additional context in comments.

2 Comments

how could i make it replace the text with the json
@SkrtOnDiscord which text exactly?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.