title: pass localStorage value into php
body: <p>I have a page which generates a chart. I have a button which generates a pdf report for it. I wanted to create an image of this chart and insert it into the pdf. To create the image, I use  <code>html2canvas</code> and get the dataurl which I store in the <code>localstorage</code>. </p>
  
  <pre><code>chart.php
  &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"&gt;&lt;/script&gt;
  
  &lt;script type="text/javascript"&gt;
     $(document).ready(function() {
          $('#download').click(function() {
               $.ajax({
                  type: "POST",
                  url: "pdfGen.php",
                  data: 'hello',
                  success: function(data) {
                      alert("hi");
                  }
                });
           });
     }); //END $(document).ready()
  &lt;/script&gt;
  
  &lt;script&gt;
    //&lt;![CDATA[
    (function() {
       window.onload = function(){
           html2canvas(document.getElementById('chart'), {
                "onrendered": function(canvas) {
                     var img = new Image();
                     img.onload = function() {
                         img.onload = null;
                         console.log(canvas.toDataURL("image/png"));
                         window.localStorage.setItem("imgURL", canvas.toDataURL("image/png"));
                     };
                     img.onerror = function() {
                         img.onerror = null;
                         if(window.console.log) {
                             window.console.log("Not loaded image from canvas.toDataURL");
                         } else {
                             //alert("Not loaded image from canvas.toDataURL");
                         }
                     };
                     img.src = canvas.toDataURL("image/png");
                 }
              });
           };
       })();
  //]]&gt;
  &lt;/script&gt;    
  &lt;body&gt;
     &lt;a href="pdfGen.php" id="download" class="button"&gt;Report&lt;/a&gt; 
     ..more code to generate the chart
  &lt;/body&gt;
  </code></pre>
  
  <p>The download button calls the pdfGen.php script which uses fpdf to generate a report. 
  pdfGen.php</p>
  
  <pre><code>&lt;?php
      echo $_POST['data']; //gives error
      /*$pdf = new FPDF();
      $pdf-&gt;AddPage();
  
      //over here I want to add the image from the chart.php page whose data url is now in the localstorage.
      ..more code to generate report
      $pdf-&gt;output();*/
   ?&gt;
  </code></pre>
  
  <p>How do I get the image inside the php script? I try to make the ajax call but I get <code>undefined index data</code> in pdfGen.php script. I got the alert HI but could not get the data on the server.
  It does not seem to work.</p>