title: jQuery, Codeigniter and DOMPDF: Anchor works but not AJAX
body: <p>I have the following anchor tag that when pressed, successfully calls a function (my_pdf) within the controller (main).</p>
  
  <pre><code>&lt;a href="main/my_pdf"&gt;Press Me&lt;/a&gt;
  </code></pre>
  
  <p>Here's the function in the main controller:</p>
  
  <pre><code>    function my_pdf()
  {
      $this-&gt;load-&gt;helper('dompdf');
      $this-&gt;load-&gt;helper('file');
      $html = "&lt;p&gt;Testing&lt;/p&gt;";
      pdf_create($html, 'somefilename');
  
      echo "Your PDF has been created.";
  }
  </code></pre>
  
  <p>The <a href="http://code.google.com/p/dompdf/" rel="nofollow">DOMPDF library</a> works and creates the file "somefilename.pdf" as expected when it is called by an anchor tag or when browsing to the controller/function from the URI as follows:</p>
  
  <pre><code>http://localhost/main/my_pdf
  </code></pre>
  
  <p>Instead of the anchor, however, I need to call this function from a jQuery AJAX request.  Here is the html:</p>
  
  <pre><code>&lt;div id="pdf"&gt;&lt;img src="assets/images/pdf-icon.gif" /&gt;&lt;/div&gt;
  &lt;div id="notice"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>and supporting jQuery:</p>
  
  <pre><code>    $('#pdf').click(function(){
      $.ajax({
          url: 'main/my_pdf',
          type: 'POST',
          success: function(msg) {
              $('#notice').html(msg);
          }
      });
      return false;//toggled this between true/false and still not working
  });
  </code></pre>
  
  <p>If I comment out the pdf_create call in the my_pdf function, I confirmed that the AJAX call returns the echo string to the  as expected.  The problem is that when I use AJAX to call main/my_pdf, the pdf is not created.  In fact, it appears that pdf_create returns a long string of code to  that is likely supposed to be used to render the pdf.  The AJAX success message returns the following string:</p>
  
  <blockquote>
    <p>%PDF-1.3 1 0 obj &lt;&lt; /Type /Catalog /Outlines 2 0 R /Pages 3 0 R /OpenAction 8 0 R >> endobj 2 0 obj &lt;&lt; /Type /Outlines /Count 0 >> endobj 3 0 obj &lt;&lt; /Type /Pages /Kids [6 0 R ] /Count 1 /Resources &lt;&lt; /ProcSet 4 0 R /Font &lt;&lt; /F1 9 0 R >> >> /MediaBox [0.000 0.000 612.000 792.000] >> endobj 4 0 obj [/PDF /Text ] endobj 5 0 obj &lt;&lt; /Creator (DOMPDF) /CreationDate (D:20110225190447-05'00') /ModDate (D:20110225190447-05'00') >> endobj 6 0 obj &lt;&lt; /Type /Page /Parent 3 0 R /Contents 7 0 R >> endobj 7 0 obj &lt;&lt; /Length 73 >> stream 0.000 0.000 0.000 rg BT 34.016 723.208 Td /F1 12.0 Tf [(Testing) </p>
  </blockquote>
  
  <p>I'm open to any suggestions.</p>