You need to research the lifecycle of a PHP request. When you submit your ajax request, the success callback is called with one argument contained the output you expect:
Test<br>=<html data here>
But, when you redirect to pdf.php, you are in effect sending another request. This other request has no post variables so $_POST['html'] is an empty string.
Try changing the success function to this:
succes: function(data) { console.log(data); alert('Done!'); }
Then, open the page. Once you see "Done!", check the javascript console in firebug. You should see your expected result.
Here's a timeline of what your page does:
makePDF() is called POST request is sent to pdf.php with POST variables: {html: 'content goes here'} pdf.php returns Test<br>=content goes here - The AJAX request calls your success function with the first argument being return value of
pdf.php (Test<br>=content goes here) - Your javascript redirects the user agent to
pdf.php - GET request is made to
pdf.php with NO variables pdf.php returns (and shows in your browser) Test<br>= because $_POST['html'] is empty at this point
Now why the second time does pdf.php not return the value it returned the first you ask? Because HTTP is a stateless protocol. That means one request to pdf.php is entirely different from another. Without the use of GET, POST, or SESSION variables (cookies included), one request to pdf.php has no knowledge to any other requests to pdf.php.
Also, I believe you are misusing AJAX in this instance. The intent of AJAX is to perform requests to the server without having to navigate to a new page. You should either perform the ajax request and then take the returned data and inject it into the current page (you can use the first parameter passed to the success function) or forego AJAX altogether and just redirect to pdf.php.
data: {'html': html},is better written asdata: {html: html},{foo-bar: 'stuff'}works as expected (which it introduces ambiguity so it won't). There is a reason why the JSON standard requires that all object keys be quoted.