Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

231
Views
El código JavaScript se ejecuta en node.js pero no en el navegador

tengo este codigo:

 async function my_function() { console.log("Hello"); let response = await fetch(url, { mode: 'no-cors' }) .then(response => response.json()) // THIS LINE .then(response => { console.log(response); }) }

que funciona muy bien si const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); en node.js. Sin embargo, esto no se ejecuta en el navegador. Cuando ejecuto este código en Google Chrome me sale este error

 Uncaught (in promise) SyntaxError: Unexpected end of input

en relación con el

 .then(response => response.json()) // THIS LINE

línea. ¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Para el navegador, debe habilitar la política cors; de lo contrario, no funcionará. Entonces, en su API, debe incluir:

 "Access-Control-Allow-Origin" : "*",

Y también deshabilite el modo sin cors.

about 4 years ago · Juan Pablo Isaza Report

0

¿Porque mezclas Promises con await? Elección uno de. Lea sobre esto https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Async_await

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!