Use AJAX. The following uses jQuery:
if(confirm('Are you sure?')) {
$.ajax({
url: '/path/to/file.php',
data: 'url=encoded&query=string', // Can also be an object
success: function(output) {
// This function is called after the PHP file completes.
// The variable passed in is a string containing all output of
// your PHP script (i.e. echo / print )
}
});
}
For more information, check out jQuery's documentation for AJAX. If you cannot use jQuery, there are many tutorials on using native JavaScript to make AJAX Requests.
If you are returning a large amount of data back to your success function from PHP, it would be worthwhile for you to return the data from PHP as a JSON encoded array, which can be safely parsed client-side into a JavaScript object.