ajax json演示

part of my page under div#posts is updated according to script results. it is an old fashioned mysql select query with echoing all the resulting tags.

e.g. foreach($output as $view) echo "{$view['smthing']} ";

what my lame programming ass have heard today is that this approach is archaic, and that instead should be used json and ajax functionality to build actual repetitious html structure on client side instead doing it on server side. i know how ajax works, and what json syntax looks like, but still i would appreciate an living example of correlation between the two in questions to boost my project's performance.

many thanks

Here is my plan. When you need to update you could send an array of JSON objects. Each JSON object would be one update. So if you need to update a table each JSON object could be a row in the table. Once your javascript has revived the data iterate over the JSON object and process them.

Personally if you have something that works and there are no performance issues i would not see the reason to do something different.

I think what you're looking for is an AJAX call to a service on the server that returns JSON, which, on the client, you merge into a template to create the HTML that you append to the DIV in question.

Dave Ward (Encosia) has some excellent tutorials on that. These might be ASP.NET on the server side, but since you're asking about the JSON, HTML and client side merging I think these will help you:

http://encosia.com/2010/10/05/using-external-templates-with-jquery-templates

http://encosia.com/2010/11/10/composition-with-jquery-templates-why-and-how

http://encosia.com/2010/12/02/jquery-templates-composite-rendering-and-remote-loading