php array to external page using jquery
<p>I have a php page to creates a multi-dimentional array called <code>$results</code>.</p>

<p>I would like to:</p>

<ol>
<li>catch submit of a form button</li>
<li>override default behavior of the submit using jQuery</li>
<li>copy and process $results on separate php using $.post</li>
</ol>

<p>I have this which is not currently working and am not sure why?:</p>

<pre><code>&lt;form id='download_to_excel' method="post"&gt;
    &lt;input type="image" name="submit" value="submit" id='xls_download_button' src='images/common/buttons/download.png'&gt; 
&lt;/form&gt;

&lt;?php 
    $json_results = json_encode($results);
?&gt;

&lt;script type='text/javascript'&gt;
    $(document).ready(function(){ 
        alert($json_results);
        $("#xls_download_button").click(function(e){ 
            alert('clicked');
            e.preventDefault(); 
            download_xls(); 
        }); 

        function download_xls(){
            $.post('./libs/common/export_data_to_excel.php', {json_data : json_results};
        }
    }); 
&lt;/script&gt;
</code></pre>

<p>When selecting the <code>xls_download_button</code>, the <code>alert()</code> never fires nor does any data get passed to <code>export_data_to_excel.php</code></p>

<p>The export_data_to_excel.php file has the following:</p>

<pre><code>&lt;?php 
$results = json_decode($_POST['json_data']);
#include the export-xls.class.php file
require_once('export-xls.class.php');
$date = date('Y-m-d');
$filename = "contacts_search_$date.xls"; // The file name you want any resulting file to be called.
#create an instance of the class
$xls = new ExportXLS($filename, $results);
#lets set some headers for top of the spreadsheet
$header = "Searched Contact Results"; // single first col text
$xls-&gt;addHeader($header);
#add blank line
$header = null;
$xls-&gt;addHeader($header);
$header = null;
$row = null;
foreach($results as $outer){
   // header row
   foreach($outer as $key =&gt; $value){
     $header[] = $key; 
   }
  // Data Rows
  foreach($outer as $key =&gt; $value){
    $row[] = $value;
  }
  $xls-&gt;addRow($header);//add header to xls body
  $header = null;
  $xls-&gt;addRow($row); //add data to xls body 
  $row = null;
} 
# You can return the xls as a variable to use with;
# $sheet = $xls-&gt;returnSheet();
#
# OR
#
# You can send the sheet directly to the browser as a file 
#
$xls-&gt;sendFile();
?&gt;
</code></pre>

<p>I do know that the <code>$json_results</code> does display proper JSON encoded values when echoed. But from there are not sure why the rest of the javascript does not run; the alerts never fire nor does the JSON data get passed? </p>

<p>Can you see why this isn't working?</p>
