testmvc.js 739 B

123456789101112131415161718192021222324252627282930313233
  1. // testmvc.js
  2. const xhr = new XMLHttpRequest();
  3. xhr.open('GET', '/appsmvc/testmvc.json', false); // Adjust the path as needed
  4. let data = [];
  5. xhr.onload = function () {
  6. if (xhr.status >= 200 && xhr.status < 300) {
  7. try {
  8. const json = JSON.parse(xhr.responseText);
  9. // Mapping the new JSON structure into the data array
  10. data = Object.entries(json).map(([key, value]) => {
  11. return { key, value };
  12. });
  13. } catch (error) {
  14. console.error('Failed to parse JSON');
  15. }
  16. } else {
  17. console.error('Failed to load JSON data');
  18. }
  19. };
  20. xhr.onerror = function () {
  21. console.error('Network error');
  22. };
  23. xhr.send();
  24. export default data;