Guest User

Untitled

a guest
Feb 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. [
  2. {
  3. "id" : 1,
  4. "name" : "Test 1",
  5. "author": "John Doe",
  6. "author_url": "https://example.com/john-doe"
  7. },
  8. {
  9. "id" : 2,
  10. "name" : "Test 2",
  11. "author": "Jane Smith",
  12. "author_url": "https://example.com/jane-smith"
  13. },
  14. {
  15. "id" : 3,
  16. "name" : "Test 3",
  17. "author": "Peter Parker",
  18. "author_url": "https://example.com/parker"
  19. },
  20. {
  21. "id" : 4,
  22. "name" : "Test 4",
  23. "author": "Bruce Wayn"
  24. }
  25. ]
  26.  
  27. var req = new XMLHttpRequest();
  28. req.open('GET', document.baseURI + '/test.json');
  29. req.onload = function() {
  30. var data = JSON.parse(req.responseText), index;
  31.  
  32. if (modal.innerHTML === '') {
  33. // This can be ignored
  34. // This is a snippet to find which data is to be inserted
  35. for (var i = 0; i < data.length; i++) {
  36. if (data[i].id == dataName) {
  37. index = i;
  38. }
  39. }
  40.  
  41. // Here is the issue
  42. var htmlData =
  43. `<div class="modal">
  44. <div class="modal-head">
  45. <h2>` + data[index].name + `</h2>
  46. </div>
  47. <div class="modal-body">
  48. <div class="content">
  49. <div class="align-center">
  50. <h3>` + data[index].name + `</h3>
  51. </div>
  52. <p class="mt-10 mb-10"><span style="color: black">Author : </span><a class="link-red" href="` + data[index].author_url + `">` + data[index].author + `</a></p>
  53. </div>
  54. </div>
  55. </div>`;
  56.  
  57. modal.innerHTML = htmlData;
  58. }
  59.  
  60. }
Add Comment
Please, Sign In to add comment