I am currently working on a small web application which includes a calendar displaying its entries. When the page gets loaded, the calendar gets generated through PHP.
On the same page, there is a form which allows one to edit the entries. The command to change gets sent by AJAX, and then the calendar has to be reloaded in some way.
What I am wondering about currently is the following:
I have two possibilities of updating the Calendar through AJAX.
- One is to send the Calendar's HTML Markup anew, whether it means reloading the entire calendar or the element of the calendar entry.
This is probably not optimal, since it requires quite a bit of (raw) data sent through the AJAX call.
On the other side, all it requires is for me to call the same PHP function which generates the markup again, return that and then replace the DOM Element on the clientside, so neccesary work is roughly 5 lines of code.
This is the way I am currently using since it feels "easier". - The other is to send the Data of the new Calendar entry JSON encoded, and then make the neccesary changes through a javascript function into the existing markup.
This also feels not optimal, since I would have to use a lot knowledge of the markup twice: Once in the PHP code and once in the JS Code. I can see this redundant code causing problems as soon as the markup would change in any way.
It also feels like a more 'complicated' solution, which includes easily 4-5 as much code considering I have to manipulate a good amount of fields (roughly 10+).
On the other hand, a lot less data gets transmitted since only the content gets sent.
Which is the better solution? Am I missing a third (or even fourth) option?