Processing caching with JSON

Source: Internet
Author: User
Tags html page json

Data validation is the most challenging and ever-changing part of every enterprise Web application. Typically validating metadata causes the JavaScript module to be mixed with server-side code. In this article, you will learn how to cache metadata in the client's best way with the help of server code, which will provide string metadata in the form of JSON (JavaScript Object notation). This approach also allows for multiple-valued and multiple-group properties to be handled in an Ajax-like manner.

Each application is developed to address an area of problem. Each domain has its own set of rules and specifications for constraining data. When an application applies these constraints to data, the constraint is validated. All applications need to validate the data entered by the user.

Currently, applications typically use a combination of IF-ELSE statements to validate data. These statements contain validation data that the developer has hard-coded or placed through server-side code. Typically, developers use server-side code to avoid subtle data changes that could result in JavaServer Page (JSP).

You can use JavaScript Object notation (JSON) to group and cache metadata, and to use JavaScript functions to access metadata to validate user input.

When there are scattered metadata in JavaScript, you cannot control how much data the server evaluates and how much data is passed to the client. All server-side code fragments are evaluated and sent to the server. However, when you use JSON to cache data, you have full control over the amount of metadata sent to the client, because the server-side code generates metadata in JSON form. This helps to send metadata only to clients that correspond to the users who see or enter data.

You can also use JSON to cache data entered by a user. After the program caches the data, it erases the data field instead of refreshing the screen, similar to Ajax. In this way, a user can enter another set of data for the same property.

Let's explore how to use JSON to cache metadata.

JSON Overview

Using JSON (that is, JavaScript Object notation), JavaScript objects are represented in a specific string form. If you assign a string with such a form to any JavaScript variable, the variable then references an object that is built by the string that is assigned to the variable.

For example, suppose you have a policy object that has the following properties:

Plan Name

Describe

Duration

You can use this JSON-form string to represent the policy object:

{"Plane": {"Cover"}, "Description": {"The Best Life Insurance Plan"}, "Term": {"Years"}}

If you assign this string to any one of the JavaScript variables, the variable will accept the data in this object unit. To access data, provide the path to the property that you want to access. For this example, assign the above string to a variable named policy:

var policy = {"Plane": {"Full Life Cover"}, "Description": {"The Best Life Insurance Plan"}, "Term": {"Years"}}

Paste the string into the title section of the HTML page, and then write the following alert:

Alert (policy. Plan)

If you view this page in any JavaScript-enabled browser, you will see an alert showing the policy plan.

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.