JavaScript-I want to make changes to the site directly on the browser side, but after the refresh it initializes

Source: Internet
Author: User
Keywords Javascript php css html
Tags php server
For example, I JS write click event, click to add a line of text on the Web page, but after refreshing the text disappears.
Do I need to use PHP if I want to keep a permanent change?

Reply content:

For example, I JS write click event, click to add a line of text on the Web page, but after refreshing the text disappears.
Do I need to use PHP if I want to keep a permanent change?

A reasonable posture should be:

    1. jsNew content is added to the Client (node in the subject dom ), and the ajax server-side data changes should be informed

    2. The next time the page is refreshed, the server side (in this case php ) renders the page based on the new data with the last node added on the client

Suggest to look at a bit more web development articles or books

Browser only parses and renders the contents of a Web page source file

The content of the code will naturally be erased. Unless, you put it there somewhere:

    • exists on the server side. Get it with Ajax.

    • There is localstorage. Get it with the Localstorage API.

I think your scenario should be similar to that of a larger form, and when the user accidentally closes the window by mistake, save the content that he filled in.
This situation is good for local storage, Localstorage/sessionstorage/cookie.
Of course, send to the background can also, but will increase the workload in the background, your backstage staff is not willing to do.

Theoretically in your page, the content area that needs to be dynamically appended should be a dynamic display area whose content needs to be stored on the server side.
JS dynamic Append effect is to reduce the data and server-side interaction, the user waits too long, affecting the user experience, so JS click on an event with two actions:
1. Dynamically add content to the DOM node of the page (the user immediately sees the effect)
2. Submit content to server-side processing (data filtering, storage, etc.) via Ajax, form submission and other technologies
When the user refreshes the page, the dynamic area is parsed by the PHP server and the latest content is displayed to ensure that the data is not lost.

It has nothing to do with PHP, and many languages can handle post and get requests.
Solution: Store to server or local chant.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.