Ajax: Embrace JSON and let XML go away

Source: Internet
Author: User
Ajax: hug JSONTo let XML go (convert)

We can share this with you. Ún & dotbwwww.cnntec.com úää y {u % O ö
PS: I amJSONI hope I can withstand the temptation of it. Amitabha, tianzun, Amen... ún & dotbww.cnntec.com úää y ~u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
Ajax (Asynchronous JavaScript and XML) is a technology in which browsers asynchronously read XML content from servers. The current technology is related to XML, and the concept is used as a joke, just like a gold outfit. The people outside the door were very busy, but the people inside the door shook their heads. What about XML? In fact, xml = TXT. XML is just a text that conforms to many specifications. It is nothing, but a file that saves characters. The browser asynchronously reads only the text content on the server, so you do not have to stick to XML during Ajax development. [Copyright, www. Jialing.Net] Ún & dotbwwww.cnntec.com úää y {u % O ö
  JSONThe origins of ún & dotbwwww.cnntec.com úää y {u % O ö
XML is used to format data. Is there any better way if we don't need XML? The answer is:JSON. IntroductionJSONI will introduce the Javascript script language first. The scripting language has its own talent for dynamic execution. That is, we can place the statement we want to execute in the string and execute it through the dynamic execution function eval. The content in the string will be executed like the script we wrote. Ún & dotbwwww.cnntec.com úää y {u % O ö
Example 1:Copy content to clipboardCode: <HTML> ún & dotbwwww.cnntec.com úää Y u % O ö
<Head> ún & dotbwwww.cnntec.com úää y {u % O ö
<Title> eval Example 1 </title> ún & dotbww.cnntec.com úää y {u % O ö
</Head> ún & dotbwwww.cnntec.com úää Y u % O ö
<Body> ún & dotbwwww.cnntec.com úää y {u % O ö
<SCRIPT> ún & dotbwwww.cnntec.com úää y {u % O ö
STR = "alert ('hello')"; ún & dotbww.cnntec.com úää y {u % O ö
Eval (STR); ún & dotbwwww.cnntec.com úää Y u % O ö
</SCRIPT> ún & dotbwwww.cnntec.com úää Y u % O ö
</Body> ún & dotbwwww.cnntec.com úää Y u % O ö
</Html> ún & dotbwwww.cnntec.com úää Y u % O ö
The Hello window is displayed. Ún & dotbwwww.cnntec.com úää y {u % O ö
We can put any script statement in the string, including the declaration statement:Copy content to clipboardCode: ún & dotbwwww.cnntec.com úää y {u % O ö
<HTML> ún & dotbwwww.cnntec.com úää y {u % O ö
<Head> ún & dotbwwww.cnntec.com úää y {u % O ö
<Title> eval Example 2 </title> ún & dotbww.cnntec.com úää y {u % O ö
</Head> ún & dotbwwww.cnntec.com úää Y u % O ö
<Body> ún & dotbwwww.cnntec.com úää y {u % O ö
<SCRIPT> ún & dotbwwww.cnntec.com úää y {u % O ö
Define = "{Name: 'Michael ', email: '17bity @ gmail.com'}"; ún & dotbwwww.cnntec.com úää y æ U % O ö
Eval ("Data =" + define); ún & dotbww.cnntec.com úää y {u % O ö
Alert ("name:" + data. Name); ún & dotbww.cnntec.com úää y {u % O ö
Alert ("Email:" + data. Email); ún & dotbww.cnntec.com úää y {u % O ö
</SCRIPT> ún & dotbwwww.cnntec.com úää Y u % O ö
</Body> ún & dotbwwww.cnntec.com úää Y u % O ö
</Html> ún & dotbwwww.cnntec.com úää Y u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
If the text that we send asynchronously in the background is a javascript declaration statement, can it be parsed without an eval method? How efficient is this process for parsing complex XML! Ún & dotbwwww.cnntec.com úää y {u % O ö
Now let's tell you what isJSON: JavaScript Object Notation. I prefer to translate it into JavaScript Object declaration. For example, to load some address book information from the background, if it is written as XML, as follows:Copy content to clipboardCode: ún & dotbwwww.cnntec.com úää y {u % O ö
<Contact> ún & dotbwwww.cnntec.com úää y {u % O ö
<Friend> ún & dotbwwww.cnntec.com úää y {u % O ö
<Name> Michael </Name> ún & dotbwwww.cnntec.com úää y {u % O ö
<Email> 17bity@gmail.com </Email> ún & dotbwwww.cnntec.com úää y {u % O ö
Http://www.jialing.Net</Homepage> ún & dotbwwww.cnntec.com úää y æ U % O ö
</Friend> ún & dotbwwww.cnntec.com úää Y u % O ö
<Friend> ún & dotbwwww.cnntec.com úää y {u % O ö
<Name> JOHN </Name> ún & dotbwwww.cnntec.com úää y {u % O ö
<Email> john@gmail.com </Email> ún & dotbwwww.cnntec.com úää y {u % O ö
<Homepage> http://www.john.com/</Friend> ún & dotbwwww.cnntec.com úää Y u % O ö
<Friend> ún & dotbwwww.cnntec.com úää y {u % O ö
<Name> Peggy </Name> ún & dotbwwww.cnntec.com úää y {u % O ö
<Email> peggy@gmail.com </Email> ún & dotbwwww.cnntec.com úää y {u % O ö
<Homepage> http://www.peggy.com/</Friend> ún & dotbwwww.cnntec.com úää Y u % O ö
</Contact> ún & dotbwwww.cnntec.com úää Y u % O ö
WriteJSONWhat about:Copy content to clipboardCode: {ún & dotbwwww.cnntec.com úää y {u % O ö
Name: "Michael", ún & dotbwwww.cnntec.com úää y æ U % O ö
Email: "17bity@gmail.com", ún & dotbwwww.cnntec.com úää y æ U % O ö
Homepage: "http://www.jialing.Net"Ún & dotbwwww.cnntec.com úää y {u % O ö
}, Ún & dotbwwww.cnntec.com úää y {u % O ö
{Ún & dotbwwww.cnntec.com úää y {u % O ö
Name: "John", ún & dotbwwww.cnntec.com úää y æ U % O ö
Email: "john@gmail.com", ún & dotbwwww.cnntec.com úää y æ U % O ö
Homepage: "http://www.jobn.com" ún & dotbwwww.cnntec.com úää y {u % O ö
}, Ún & dotbwwww.cnntec.com úää y {u % O ö
{Ún & dotbwwww.cnntec.com úää y {u % O ö
Name: "Peggy", ún & dotbwwww.cnntec.com úää y æ U % O ö
Email: "peggy@gmail.com", ún & dotbwwww.cnntec.com úää y æ U % O ö
Homepage: "http://www.peggy.com" ún & dotbwwww.cnntec.com úää y {u % O ö
} Ún & dotbwwww.cnntec.com úää y {u % O ö
The simplest is not just expression, but the most important thing is to discard the confusing Dom parsing. As long as it complies with the Javascript statement specification, commit Crip will automatically resolve it for you. Use in AjaxJSONThe basic method is to load the string of the JavaScript Object declared in the background at the front end, convert it to the actual object using the eval method, and update the page information through DHTML. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
JSONFormat
Ún & dotbwwww.cnntec.com úää y {u % O ö
  JSONThe basic format of the image is as follows:JSON. Org: ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
· An object is a set of attributes and value pairs. An object starts with "{" and ends "}". Each attribute name and value is separated by a ":" prompt, and. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
· An array is a set of ordered values. An array starts with "[", ends with "]", and values are separated. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
· The value can be a string, number, true, false, or null in quotation marks, or an object or array. These structures can be nested. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
· The definition of a string is basically the same as that of C or Java. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
· The definition of numbers is also basically the same as that of C or Java. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö

Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
JSONVs XML ún & dotbwwww.cnntec.com úää y {u % O ö
· Readability ún & dotbwwww.cnntec.com úää y {u % O ö
  JSONIt is comparable to the readability of XML. One side is the suggested syntax, and the other side is the standard tag form, which makes it difficult to win or lose. Ún & dotbwwww.cnntec.com úää y {u % O ö
· Scalability ún & dotbwwww.cnntec.com úää y {u % O ö
XML is inherently highly scalable,JSONOf course, there is nothing XML can be expanded,JSONNo. Ún & dotbwwww.cnntec.com úää y {u % O ö
· Encoding difficulty ún & dotbwwww.cnntec.com úää y {u % O ö
Rich XML EncodingToolsSuch as dom4j and JDOM,JSONYesJSONProvided by. orgTools,JSONThe encoding is much easier than XML, even if you do not useToolsCan also be writtenJSONBut it is not easy to write the XML. Ún & dotbwwww.cnntec.com úää y {u % O ö
· Decoding difficulty ún & dotbwwww.cnntec.com úää y ~u % O ö
XML parsing has to consider the parent node of the child node.JSONThe resolution difficulty is almost 0. There is nothing to say about XML. Ún & dotbwwww.cnntec.com úää y {u % O ö
· Popularity ún & dotbwwww.cnntec.com úää y ~u % O ö
XML has been widely used in the industry, andJSONBut in the particular field of Ajax, the future development of XML must beJSON. Then Ajax should become ajaj (Asynchronous JavaScript andJSON. Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
Ún & dotbwwww.cnntec.com úää y {u % O ö
Ajax is not mysterious: uncover various Ajax controls and class libraries Author: Source: mobile network responsibility Editor: fangfangún & dotbwwww.cnntec.com úää y policu % O ö
There are too many Ajax controls and class libraries now. Without knowing it, the mystery and complexity of Ajax have been added. Many people in the version are puzzled and worried about this, I decided to post this post to talk about my views on AJAX, hoping to give you an essential understanding of Ajax. Ún & dotbwwww.cnntec.com úää y {u % O ö
Viewpoint 1: Ajax and server-side technologies are irrelevant to ún & dotbww.cnntec.com úää y æ U % O ö
Strictly speaking, compared with traditional web development, Ajax is a complete Client technology. Because many controls encapsulate the communication process between the client and the server, many problems also arise due to communication. In fact, no matter what Ajax technology is, the server side returns a pure text stream, which is then processed by the client. The text can be in XML format, HTML snippets, JavaScript scripts, or strings. The server is just a data interface. The client uses the XMLHTTPRequest object to request this page. The server writes the result text to the page. This process is no different from that of common web development. The difference is that after the client asynchronously obtains the result, it is not directly displayed on the page, but is processed by the client's Javascript script and then displayed on the page. Various controls can returnDatasetObjects, date objects, or other data types encapsulate the results of this processing process. Ún & dotbwwww.cnntec.com úää y {u % O ö
Viewpoint 2: Dom model is the most essential technology of Ajax.
The reason why XMLHttpRequest is not listed as the most essential technology is that I think it is too simple. It only allows the browser to request a page in the background and send its content to JavaScript for processing. The true core should be the DOM model, that is, the Document Object Model. In the DOM model, HTML tags are considered to be an object, such as a div object or a table object. The Dom model defines the attributes, methods, and events of these objects. Through these properties, you can modify the content of a page that has been displayed in a browser, such as adding nodes, modifying node locations, and deleting nodes. It is not just an innerhtml attribute, although it is a very useful attribute. Ún & dotbwwww.cnntec.com úää y {u % O ö
Viewpoint 3: understanding their implementation before using Ajax controls ún & dotbwwww.cnntec.com úää y æ U % O ö
The use of Ajax controls can indeed improve efficiency, but if you use controls like a castle in the air, it will be worth the candle. Switching from one control to another has a long learning curve. Therefore, we should understand it from the underlying layer. Besides, Ajax is not an advanced technology. In fact, the bottom layer of everything is actually simple, but if these underlying things are encapsulated, things will become complicated and hard to understand. Use ASP.NetFor example, the custom feature makes it possible to add a sign like [Ajax method] before a method to call it an asynchronous method. I believe this makes ASP.NetAjax development is more "efficient" or "mysterious", and more things are encapsulated. Remember the same one. Any request to the server only returns plain text. We do not have to rely on encapsulated processing, but can implement it by ourselves. Ún & dotbwwww.cnntec.com úää y {u % O ö
Opinion 4: Learn JavaScript ún & dotbwwww.cnntec.com úää y æ U % O ö
In most people's opinion, JavaScript is not such a formal language. Anyone who has learned C can understand it at a glance, in addition, there are often Script Error prompts in the browser, so the subconscious feels that it cannot take too much responsibility. In fact, it is totally wrong to learn Ajax well. Javascript, as a scripting language, does not have very strict syntax, but does not prevent it from completing many complex tasks. Without JavaScript, there is no Ajax. So I strongly suggest that, before learning Ajax, be sure to study some JavaScript, in general, if you can smoothly understand the prototype framework code (such as: prototype-1.3.1.js ), your JavaScript level has basically passed. At the same time, you can have a basic understanding of the DOM model. Ún & dotbwwww.cnntec.com úää y {u % O ö
Opinion 5: Ajax embellishment: CSS ún & dotbwwww.cnntec.com úää y æ U % O ö
Using JavaScript to control CSS is actually very simple. Basically, each DOM object has a style object, as long as the "-" in the CSS attribute is removed, and the subsequent letters can be used as attributes, for example, element. style. backgroundcolor = "# f00"; in CSS, select {background-color: # f00} ún & dotbwwww.cnntec.com úää y æ U % O ö

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.