title: jQuery - use of a global function
body: <p>In an HTML page, having two buttons (EDIT, DELETE), I do an AJAX call then I parse the returned JSON and I do perform an EDIT or a DELETE based on the returned ID. All this inside of a</p>
  
  <pre><code>$( document ).ready(function() {
      ...
      $('button.icons8.icons8-edit-file').on("click", function(){
          var key = $(this).attr('key');
          $.ajax({
              url: '/ede/' + key + '/json',
              method: 'POST',
              success: function (response) {
                  // PARSING THE JSON, EXTRACTING THE ID FROM IT
                  // AND PERFOMING THE EDIT
              }
          });
      })
      ...
      $('button.icons8.icons8-delete-file').on("click", function(){
          var key = $(this).attr('key');
          $.ajax({
              url: '/ede/' + key + '/json',
              method: 'POST',
              success: function (response) {
                  // PARSING THE JSON, EXTRACTING THE ID FROM IT
                  // AND PERFOMING THE DELETE
              }
          });
      })
      ...
  });
  </code></pre>
  
  <p>What I would like to have is a global function what gets the key value, does the AJAX call and returns a value according to a pattern.</p>
  
  <pre><code>$( document ).ready(function() {
      ...
      $('button.icons8.icons8-edit-file').on("click", function(){
          var key = $(this).attr('key');
          var value = GLOBAL_FUNCTION(key, pattern_edit);
          // PERFOMING THE EDIT
      })
      ...
      $('button.icons8.icons8-delete-file').on("click", function(){
          var key = $(this).attr('key');
          var value = GLOBAL_FUNCTION(key, pattern_delete);
          // PERFOMING THE DELETE
      })
      ...
  });
  </code></pre>
  
  <p>Where sould I put that <strong>GLOBAL_FUNCTION(p_key, p_pattern)</strong> fuction? Inside or outside of the <strong>ready</strong> function? How do I return the response from this global function? What if the result of parsing the response produces a list of values?</p>