title: Ajax Javascript Function to execute PHP Code on Button Press
body: <p>I'm running the following Javascript function (from within a PHP script hence the echo):</p>
  
  <pre><code>echo'&lt;script type="text/javascript"&gt;';  
  echo'//Execute PHP Copy Script';
  echo'function do_copy(){';
  echo'var xhReq = new XMLHttpRequest();';
  echo'var request = "../wp-content/plugins/upCustomBadges/copy.php" // prepare a request to script';
  echo'xhReq.open("GET", request, false);  // send a request';
  echo'xhReq.send(null);';
  echo'document.getElementsByID("results").innerHTML=xhReq.responseText  /// display results';
  echo'console.log(callback.toString());';
  echo'}';
  echo'&lt;p&gt;&lt;input type="button" value="Copy Badges" name="copy_badges"  onclick="do_copy()" class="button-primary"&gt;&lt;/p&gt;';
  echo'&lt;div id="results"&gt;Results';
  echo'&lt;/div&gt;';
  </code></pre>
  
  <p>It triggers a PHP script. The script works and the copy function gets triggered. However, I don't get any feedback from the Javascript function. I implemented a callback to console.log as you can see. It states:</p>
  
  <pre><code>Uncaught ReferenceError: do_delete is not defined options-general.php?page=upCustomBadges:177    onclick
  </code></pre>
  
  <p>Any help would be appreciated!</p>