title: How is the data passed from JSON to AJAX?
body: <p>I'm facing difficulties understanding the logic here. Ok, so let's say I have a class </p>
  
  <pre><code>@RequestMapping(value="/GetPersons", method = RequestMethod.GET)
      public void loadPersons(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws IOException {
          OutputStream out = response.getOutputStream();
          List&lt;Person&gt; persons = personDAO.loadPersons();
          Iterator iterator = persons.iterator();
  
          JSONObject jsonObject = new JSONObject();
          JSONArray jsonArray = new JSONArray();
          while (iterator.hasNext()) {
            JSONObject object = new JSONObject();
               object.put("name", person.GetName());
              jsonArray.add(object);
          }
          jsonObject.put("data", jsonArray);
          OutputStreamWriter writer = new OutputStreamWriter(out);
  
          try {
              writer.write(jsonObject.toString());
          }finally {
              writer.close();
          }
      }
  </code></pre>
  
  <p>And then I have a simple script in my index.jsp</p>
  
  <pre><code>function loadPersons(json) {
      var obj = JSON.parse(json);
      var Person = obj.data;
  
      for (i = 0; i &lt; myArr.length; i++) {
          $('#myId).append('&lt;li&gt;&lt;a href="#" PersonId="+Person[i].name+"&gt;Test&lt;/a&gt;&lt;/li&gt;');
  
      }
  }
  
  $.ajax({
      url: "http://localhost:8080/Persons/getPersons",
      success: function (data) {
          loadPersons(data);
      },
      error: function (xhr, ajaxOptions, thrownError) {
      }
  });
  </code></pre>
  
  <p>So my question is the following... What is the logic that goes on here? How is the JSONObject data passed to the $.ajax success and the function. The function takes an argument "data" but what is going to be passed? The whole getPersons method from the java or?</p>
  
  <p>The point here is to dynamically populate a simple dropdown by calling json object with ajax. </p>