Sunday, 15 February 2015

jquery - View in php and javascript files - MVC -



jquery - View in php and javascript files - MVC -

this .php file creates table.

<table id="contact-messages"> <thead> <tr> <th>username</th><th>category</th><th>message</th><th>created at</th> </tr> </thead> <tbody> <?php foreach ($contact_messages $message) { echo '<tr>' . '<td>' . htmlentities($message['username']) . '</td>' . '<td>' . htmlentities(ucfirst($message['category'])) . '</td>' . '<td>' . nl2br(htmlentities($message['message'])) . '</td>' . '<td class="created-at" data-created_at="' . htmlentities($message['created_at']) . '"></td>' . '</tr>'; } ?> </tbody> </table>

and .js file page. code changes content of table.

$.get("contact-messages.php", { "category": category }, function (data) { $("#contact-messages").find("tbody").empty(); // empty old messages. (var = 0; < data.length; i++) { $("#contact-messages").find("tbody") .append(($("<tr/>") .append($("<td/>", { text: ((data[i].username === null) ? '' : data[i].username) })) .append($("<td/>", { text: data[i].category })) .append($("<td/>", { text: data[i].message })) .append($("<td/>", { text: data[i].created_at, class: 'created-at', 'data-created_at': data[i].created_at })) )); } }, 'json');

so, every time want alter construction of table have alter .php , .js files. now, questions is, there way store construction of table in 1 file , every times want alter structure, alter file?

create html in php page , phone call php page using $.ajax request , utilize response coming ajax request appropriate method $("#contact-messages").html(reponse) / $("#contact-messages").append(response) / $("#contact-messages").prepend(response).

php jquery templates

No comments:

Post a Comment