"Saving" appended children?
Is there a way 开发者_开发百科to keep children added to the DOM via .appendChild() after a POST/GET without regenerating them in JavaScript? Right now I'm regenerating them with a few function calls written in a script tag using php.
If the page is reloaded, the DOM is recreated from scratch, and any earlier modifications are lost.
Possible solutions:
Use Ajax to avoid reloading the page. You would be able to send requests asynchronously without losing the state of the DOM.
When responding to specific requests, reconstruct the correct elements while rendering the HTML from php. This requires some duplicated logic on the server-side that you are now handling on the client-side.
Not if you are appending on the client side. The server has no way of knowing that the source doc has been altered, and in turn has no way to make sure the update doc is served after a GET/POST. Best analogy that I can think of is if you open a Word doc, modify some text, and then close the app without saving the file.
精彩评论