title: Ajax call produces undefined path
body: <p>I am having trouble figuring out why an ajax call i'm making to retrieve a Json file isn't working. I know this question has been asked a lot but it seems that none of the answers were able to help me, so I'm starting a new thread here.</p>
  
  <p>I am generating a drop down menu, where if selected, a database call is being made to pull information needed throughout my site. This is how I am generating the drop down items:</p>
  
  <pre><code>const dropDown = [];
  var childElement, appendChildElement, parentElement;
  
  // Add child elements
  for (var i = 0; i &lt; nameList.length; i++) {
      dropDown.push({ id: numList[i], name: nameList[i]});
  }
  parentElement = document.getElementById('myDropdown');
  
  // Add child elements
  for (let item of dropDown) {
      childElement = document.createElement('a');
      appendChildElement = parentElement.appendChild(childElement);
      appendChildElement.innerHTML = item.name;
      appendChildElement.onclick = function () {
          $.ajax({
              method: "GET",
              url: "/home/data/" + item.id,
              type: "JSON"
          } 
      ).asServiceResult(true).done(function (result) {
          alert(result);
      }).fail(function (isCommunicationError) {
          if (!isCommunicationError)
              magalert.errorMessage("Couldn't load content");
      });
      };
      //appendChildElement.addEventListener("click", item.onclick, false);
      appendChildElement.id = item.id;
      //appendChildElement.href = item.href;
  }
  </code></pre>
  
  <p>For the time being, I am just testing this with a simple alert, which I know isn't the most efficient practice but it's easy. I am trying to call the data function in my home controller, which does the following:</p>
  
  <pre><code>public IActionResult Data(int id)
              {
                  AllChapterInformation allChapterInformation = new AllChapterInformation();
                  Chapter chapter = allChapterInformation.GetChapterInformation(id);
                  return Json(chapter);
              }
  </code></pre>
  
  <p>I've tried adding [HttpGet] and playing around with attributes. I've tried changing the path, the type, basically any solution out there about this topic. And yet, the resulting path when clicking on the dropdown always produces Localhost/Undefined. Any suggestions? I feel like i'm missing something painfully obvious.</p>