title: Using AJAX to run PHP code
body: <p>I have written some JavaScript code that will read from the Google Maps API and get a list of JSON objects. It will then convert each JSON object into an XML object. A co-worker needs this list converted to XML and then appended to an existing XML file  and then save it to our server. So I wrote some PHP code to do that. </p>
  
  <p>Now this is my first time working with PHP but I managed to write that PHP code easily enough. The next thing I am trying to do is write some javascript to run the PHP file and also send the XML object over to the PHP where it can append and save the XML. I figured I would use jQuery's <code>$.ajax</code> function. I started using a simple example trying to echo a string into some <code>&lt;pre&gt;</code> tags. So here is my code:</p>
  
  <p>Javascript (Lies within index.php)</p>
  
  <pre><code>&lt;script&gt;
      var scriptString = 'THIS IS MY STRING';
      $('#clickMe').click(function(){
          $.ajax(
          {
              method:'get',
          url:'index.php',
          data:
          {
              'myString': scriptString
          }
          });
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>PHP &amp; HTML (also lies within index.php)</p>
  
  <pre><code>&lt;button type="button" id="clickMe"&gt;CLICK ME TO RUN PHP&lt;/button&gt;
  &lt;pre&gt;
      &lt;?php
          echo $_GET['myString'];
      ?&gt;
  &lt;/pre&gt;
  </code></pre>