JavaScript: Error with .then and innerHTML

0

I have errors in the following code:

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>

    <body>
        <h1 Id = "Datos"></h1>

        <script>
            fetch('http://localhost/API_PHP/backend/Datos.php')
            .then(Datos => Datos.json())
            .then(Datos => {
                document.getElementById('Datos').innerHTML = ´
                Dolar: ${Datos.Dolar} - Euro: ${Datos.Euro}
                ´
            })
        </script>
    </body>
</html>

The errors are specifically in this script:

.then(Datos => {
document.getElementById('Datos').innerHTML = ´
Dolar: ${Datos.Dolar} - Euro: ${Datos.Euro}

})

The symbols give me error and the opening keys { after the $ also and the: after Euro likewise.

I imagine the syntax is wrong, please thank me for help as I am starting hehehe

    
asked by roberthung 01.08.2018 в 17:36
source

1 answer

2

I think the only mistake you have is having the quotes upside down; try it this way and tell us:

document.getElementById('Datos').innerHTML = 'Dolar: ${Datos.Dolar} - Euro: ${Datos.Euro}'

<!DOCTYPE html>
<html>
  <head>
  </head>

  <body>
    <button type="button" onClick="alerta()">Click</button>
  </body>

<script>
  function alerta(){
    var texto = 'Mensaje';
    alert('${texto}')
  }
</script>
</html>
    
answered by 01.08.2018 / 17:43
source