Search code examples
javascriptjqueryajaxjsonstringify

.js files and the jQuery AJAX Method


If I have the following .js file, how do I call it using a jQuery AJAX method? I am familiar with using JSON files, but this is both a .js file and has similar syntax to a JSON file so it has me confused. Is the JSON.stringify() method part of the solution? While this is just sample code, I am ultimately trying to create separate arrays based on age, but that should not affect the original question.

these_records = [
  {
    "name": "sarah",
    "age": "50"
  },
  {
    "name": "mary",
    "age": "40"
  }
]

Solution

  • No need for jQuery. No need for Ajax. Just load it and use it.

    <script src="records.js"></script>
    <script>
        alert(these_records[0].name);
    </script>