title: Jquery questions about callback of ajax
body: <p>See the following code snippet:</p>
  
  <pre><code>$("#someid").autocomplete({
      source: function (req, resp) { 
          $.ajax({
              url: "/api/someapi", 
              type: "GET",
              dataType: "json",
              data: { id: req.someid },
              beforeSend : function()
              {
  
              },
              success: function (data) {
                  resp($.map(data, function (item) {
                      return {
                          label: "&lt;div class='result'&gt;" + item.name + "&lt;/div&gt;",
                          value: item.Name,
                          emailName: item.EmailName
                      };
                  }));
              }
              }
          });
      });
  </code></pre>
  
  <p>My questions are listed below:</p>
  
  <ol>
  <li>the source of ajax call is a function - <strong><em>function(req, resp)</em></strong> - does jQuery accept a function with two parameters as source data provider? Is this by default? </li>
  <li>Can any one explain the function after <strong><em>success:</em></strong>? Basically, I could get that it uses the data from ajax response; map each data to one item with some css decoration. But my question is: what's the goal of wrapping $.map with <strong><em>resp</em></strong>? </li>
  <li>We can see that there're a couple of callbacks in this code snippet. However, since I'm pretty new to jQuery, I wonder how to determine how many parameters to pass into each callback, say after <strong>source:</strong> we can have a callback with two parameters; after $.map, we can have another callback with only one parameter ?</li>
  </ol>