In my PHP project I'd like to use AJAX technology. I am familiar with simply AJAX requests and simply responses, in which only simply answer such as "1" (user exists od "2" (user doesn't exist) is provided. In these cases there is no problem to process this type of response with using of jQuery, for instance.
But in some cases, I suppose more complex responses, which force re-render huge part of the page. I have following ideas, how to do it:
Usings JSON data as the response of server-side script and process them with using of jQuery on client?
Render full HTML code on the server, send it to the client as the response to the AJAX request and simply process it in "success" part of the ajax call?
What's the best approach for preparing the response on the server for complex request? I would like to use option 2) but I would like to avoid the following syntax:
$result = '';
$result = '<div>';
$result = ' <p>Username ' . $username . ' is not unique';
$result = '</div>';
return $result;
Is there a possibility to use something like "templates" for rendering ajax response? I would like to use pure PHP, no additional frameworks.