The issue is with your use of the output buffer.
The method ob_end_clean() discards the contents of the buffer so basically your script is ending without sending anything back out in the response. From the look of your script you could safely not use a buffer at all. Just remove ob_start() from the beginning and ob_end_clean() from the end.
If there is more to your code where you do actually need to use a buffer, check out ob_get_contents() to get your output before you close the buffer or ob_end_flush() to close the buffer and output its contents in one call.