Megazoid has answered the question but I just would like to add that what you are asking is what the success clause will do in ajax technique. success: function(data) returns all the php outputs in a single variable, and in your case it’s called data
usually in ajax php I do something like this:
<?php
$response = ''; // Initialize response
....Some codes here...
echo json_encode( $response ); // Return response
?>
The reason why I use json is because you can return arrays and complex objects via json encode, otherwise I think you can only return a simple variable