title: How to send additional parameters to success function in jquery ajax
body: <p>I have the following Jquery code, I'm trying to display information in <code>$('.cbs-List').HTML(divHTML);</code> based on the region value. But in the success <em>function</em>, I can't read the value for the region, it states that </p>
  
  <blockquote>
    <p>'data is undefined'</p>
  </blockquote>
  
  <p>What is the correct form of passing parameters or values to the success <em>function</em> in this case?</p>
  
  <pre><code>$(document).ready(function() {      
      getSearchResultsREST('LA');
  });
  
  function getSearchResultsREST(region) {
      var querySA = 'ClientSiteType:ClientPortal* contentclass:STS_Site Region=LA';
      var queryDR = 'ClientSiteType:ClientPortal* contentclass:STS_Site Region=EM';
  
          if(region == 'LA') {
              var searchURL = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?queryText='" + querySA + "'";
          } else {
              var searchURL = _spPageContextInfo.webAbsoluteUrl + "/_api/search/query?queryText='" + queryDR + "'";
          }
  
          $.ajax({
              url: searchURL,
              method: "GET",
              headers: {
                  "Accept": "application/json; odata=verbose"
              },
              contentType: "application/json; odata=verbose",
              success: SearchResultsOnSuccess(data, region),
              error: function(error) {
                  $('#related-content-results').html(JSON.stringify(error));
              }
          });
      }
  
      function SearchResultsOnSuccess(data, region) {
          var results;
          var divHTML = '';
  
          if (data.d) {
              results = data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results;
  
              if(results.length == 0) {
                  $('#related-content-results').html('There is No data for the requested query on ' + _spPageContextInfo.webAbsoluteUrl);
              } else {
                  for (i=0; i&lt;results.length; i++) {
                      var item = results[i];
                      var itemCell = item.Cells;
                      var itemResults = itemCell.results;
  
                      // Get values for item result
                      var _title = getValueByKey("Title", itemResults);
                      var _path = getValueByKey("Path", itemResults);
  
                      divHTML += '&lt;li&gt;&lt;a href=' + _path + '&gt;' + _title + '&lt;/li&gt;';
                  }
  
                  // Display information based on region.
  
                  $('.cbs-List').html(divHTML);
  
              }
          }
      }
  </code></pre>