javascript - How to convert an element to a string that can be stored and restored from localStorage -


My plan is after storing your elements in local elements once (for an online app) I think that If I can get it to work, it will make my app much faster). So I came up with the following, but the material seems to be either stored or returned as zero. Now I thought that an element was originally a string, so I do not have to do anything to store it in the local store, but apparently not. Does anyone know if I can get it, then what do I want?

If you want to take it for a spin, you will need a small file which will have to be passed to HTML. Content is not important The first time it runs if (content) will evaluate for the wrong next time it is true and I added it to .clar () , made it optional . For the third time the showSource function will populate the id = localor element (which should be different from id = content element or whatever other element you choose to populate) "from the file "After the tap.

  function summary (source) {// function and related elements only for $ $ ("# local"). HTML ("& lt; p>" + source + "& lt; / p & gt;"); } // The name of the local local storage element is the ID of the element in the main form // element, where the content is generated for the source Function Load Element (local, id, source) {// to load this one element The general script for the efforts is content = localStorage.getItem (local); // Try loading from local content (content) {// if $ (id) .html (content) found; Shosource ("From Local" + Content); // localStorage.clear () was added only for testing; // only added to test / load in the #content element} else {// $} was not found. Load (source); ShowSource ("From File" + Content); // Only for trial / added // Load it from server .. localStorage.setItem (local, $ (id) .html ()); // so save it to local storage, so we do not have to do it again anytime}} $ (document) .ready (function () {loadElement ("login.1001", "#content", " Login.html ");});   

The work you are doing does not work that you are saving the item before loading it. loads works asynchronous , like all (appropriate) AJAX calls when you call load , but after the end < Em> starts process. Your code continues and is grabbing what it thinks is content and has to save it, but the content is not yet.

Use callback instead:

  $ (id) .load (source, function () {showSource ("content" from "file"); // only To test / load // it load from server .. localStorage.setItem (local, $ (id) .html)); // save it in local storage, so we do not need to do it again soon.});   

But ... Are not you modifying browser cache again?

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -