Welcome Guest, Not a member yet? Register   Sign In
Staying DRY with AJAX and PHP, maybe utilize tempaltes?
#1

[eluser]msteudel[/eluser]
I was wondering if anyone has any clever ways to use templates when utilizing AJAX/JS/PHP to create additional html elements? Right now I tend to have one place in my php where the initial page load generates the html elements, then I have another place in my js files where I use ajax to create new elements....

TIA
#2

[eluser]Simian Studios[/eluser]
Depends exactly what you want to do really.. what you could do is have some controller methods set up that render different parts of the page through their views.

Then, in your JS, you call the functions via an AJAX request and update the client with the response from the server - that way you could for example use the node builder to build an element that you then update with content via the AJAX requests.

Although, the question has to be asked why you're doing it that way specifically? I always try to build so that the app works without JS, and then the JS sits on top and enhances the behaviour, rather than being a vital ingredient.




Theme © iAndrew 2016 - Forum software by © MyBB