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

176
Views
por qué ajax recupera datos del archivo json solo si la llamada está dentro del archivo html

Estoy usando ajax para recuperar algunos datos de json. Cuando coloco un script dentro del HTML, funciona bien, pero cuando realizo una solicitud ajax desde un archivo JS, no funciona. No estoy seguro de por qué. He comprobado que el archivo json está en el mismo directorio que todos los demás archivos. Además, mi archivo HTML incluye la ruta correcta a mi archivo JS. A continuación se muestra el código con script dentro del archivo html

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="Project.css"> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src = "Project.js"></script> </head> <body> <div id="div1"> <strong><p id="loved">Secret code</p></strong> <button id="button6">click me</button> </div> <script> //ajax call to retrieve json file on everydayuse page ( that works fine) $("#button6").click(function() { $.ajax({ type:"GET", url:"package.json", dataType:"json", success:function(result) { $("#div1").html(""); $("#div1").append("Use code to receive free shipping:" + "<h3 style='color:deeppink'>"+ result.name+ "</h3>" + "By:" + "<h3 style='color: deeppink'>"+result.date+ "</h3>"); } }); }); </script> </body> </html>
over 4 years ago · Santiago Trujillo
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!