title: JQuery - Pass variables to PHP script via AJAX call and then display file
body: <p>I'm trying to generate Outlook event files for my events, doing so on the fly as and when someone requests it by pressing a link on the page.</p>
  
  <p>Here's what i've got so far, but I can't find out how to get the browser to download the content which is returned.</p>
  
  <p>I know how I could do this if I sent everything via _GET, but I'd prefer to do it via _POST, hence I'm going down this route..</p>
  
  <p>Any thoughts?
  Thanks!</p>
  
  <p><strong>HTML / Javascript</strong></p>
  
  <pre><code>&lt;script&gt;
  $(function() {
      $(".button").click(function() {
          // validate and process form
          // first hide any error messages
          var start = $("input#start").val();
          var end = $("input#end").val();
          var dataString = 'start='+ start + '&amp;end=' + end;
          $.ajax({
              type: "POST",
              url: "/calendar.php",
              data: dataString,
              success: function(data) {
                  //Need to return the file contents somehow!
              }
          });
      return false;
      });
  });
  &lt;/script&gt;
  &lt;form name="calendar" method="post" action=""&gt;
        &lt;input type="hidden" name="start" id="start" value="&lt;?php echo $start; ?&gt;" /&gt;
        &lt;input type="hidden" name="end" id="end" value="&lt;?php echo $end; ?&gt;" /&gt;
        &lt;input type="submit" name="submit" class="button" id="submit_btn" value="Outlook" /&gt;
      &lt;/fieldset&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>PHP File</strong></p>
  
  <pre><code>&lt;?php
  if (isset($_POST['start'])) {
      $start = $_POST['start'];
      $end = $_POST['end'];
      $c = header("Content-Type: text/Calendar");
      $c .= header("Content-Disposition: inline; filename=calendar.ics");
      $c .= "BEGIN:VCALENDAR\n";
      $c .= "VERSION:2.0\n";
      $c .= "PRODID:-//xxxyyyy//NONSGML //EN\n";
      $c .= "METHOD:REQUEST\n"; // requied by Outlook
      $c .= "BEGIN:VEVENT\n";
      $c .= "UID:". $start . $end ."-" . "-xxxxyyyy.com\n"; // required by Outlook
      $c .= "DTSTAMP:".date('Ymd').'T'.date('His')."\n"; // required by Outlook
      $c .= "DTSTART:20080413T000000\n"; 
      $c .= "SUMMARY:" . "\n";
      $c .= "DESCRIPTION:" .  "\n";
      $c .= "END:VEVENT\n";
      $c .= "END:VCALENDAR\n";
      echo $c;        
  } else {
      echo "Sorry you can't access this page directly";   
  }
  ?&gt;
  </code></pre>