Ajax in my eyes

Source: Internet
Author: User
Ajax was so popular last year. As the core technology of the web era, I have been engaged in winform and Windows Mobile Application Development. Although I know little about web development, however, I have never learned to develop a web system like winform, And I have recently learned asp from my spare time. net, and now I have understood the working principles of Web such as viewstate. I can say with certainty that there are still some "Masters" that web developers do not understand clearly ", of course ASP. net is not the topic discussed today. Let's look at Ajax. After understanding it clearly, you will find that it is much easier than understanding the thread units in winform programming, as far as its technology is concerned, there is no mystery or complexity, and its working mechanism is not as difficult as the three-way handshake. We do not discuss the implementation methods, and only analyzes the underlying working principle, so read this article Article Rocket building technology is not required.

Ajax (Asynchronous JavaScript and XML) Chinese meaning Asynchronous JavaScript and XML, or XML-based Asynchronous JavaScript. it provides a local webpage refresh mechanism. Compared with the traditional full-page load, it has a qualitative leap in performance. Let's look at GoogleMap and the autocomplete function in the Google input box, I believe you are fascinated by Ajax. Every technology has its development roots. Let's trace the history of Ajax. In fact, this technology was first introduced in ie5.0, and it was just a few years ago, unfortunately, Microsoft did not find its value until the research results of Flickr, backpack, and Google were amazing in this regard. Technically, Ajax only provides one function, that is, the clientCode(JavaScript) to send an HTTP request, this special function is not implemented by common developers because it depends on the browser itself. In ie5, microsoft introduced an XMLHTTP ActiveX object. Later, Mozilla, Safari, and other browsers followed suit and provided the XMLHttpRequest class. It supported the methods and Attributes provided by Microsoft ActiveX object. this class makes it possible to send HTTP requests using JavaScript. It also provides a way to insert response code. The following is the pseudo code of the object execution mechanism described above:

Request = new XMLHttpRequest ();

Request. Open ('get', 'HTTP: // localhost/xxxx. aspx, true );

Request. Send (null );

Respond to this request:

Request. onreadystatechange = function (){

VaR text = request. responsetext; // The response string.

// Respond... execute some client Javascript

};

Of course, the actual code is much more complicated than the code, but as mentioned above, we do not discuss the implementation method, but explore its execution principle, it can be seen that the simple principle of AJAX is naked after being stripped of the mystery. It is the same as the Event Response in C #, but this event is triggered by the client request and the server, the real complexity has already been encapsulated by Microsoft into ActiveX objects. However, the simplicity of the principle does not mean that the implementation is simple. It is indeed difficult to implement it, but now there are so many Ajax frameworks that have shielded us from the underlying stuff. The implementation is not discussed in this article, so we will not detail it here.

The introduction of any new technology is accompanied by a painful learning. We must master its implementation principles in order to be accurate and make good use of these new technologies. Blind use can only be self-defeating. How do we deal with the coming Ajax as a developer? The following are some conclusions after my understanding of AJAX (Note: I am very knowledgeable about the technical skills, please forgive me for any mistakes ):

Understand the problems solved by Ajax

The emergence of AJAX is to improve the web Program User Experience: the problem of page refresh latency after a user clicks a page is the direct reason for introducing Ajax. If our program uses Ajax and does not improve the user experience, it is only for Ajax and Ajax, instead of Ajax for user experience.

Disadvantages of AJAX

1. compatibility. The beginning of AJAX is the XMLHttpRequest mentioned above. However, this object is different in different browsers, which makes it more difficult for us to complete a cross-browser general code during development, the javascript language also has different technical support and standards in various browsers, thus increasing this difficulty. Fortunately, the numerous Ajax frameworks on the market have solved the compatibility problem for us and made it easy to build cross-browser programs.
2. Server pressure. I think Ajax changes the client request Server Response Process to asynchronous execution. On the one hand, it improves the user experience and significantly increases the number of user request responses, and the pressure on the server will also increase, imagine that, in the traditional full-page loading mode, when a user requests a page, it will inevitably wait for the page to load, while Ajax makes the page do not need to wait after the request is sent, in this way, the user can click another page element to send the request again. Imagine if Google's AutoComplete function is a link to the database request, this line will occur every time the input occurs. Does the database pressure multiply?
3. language problems. Because Ajax uses JavaScript as the core, and this is a complicated and error-prone language, it will allow us to freely spread the application logic on the server and client, this makes the problem hard to be discovered and the code is difficult to reuse. Javascript is even considered by server developers as something that is not needed by enterprise-level applications. Fortunately, Microsoft Script debugger and other powerful JS debuggers have emerged. At the same time, vs2008's JavaScript smart functions are also working hard for these problems. However, JavaScript defects such as the assignment of double variables (usually due to the lack of data types) Make debugging programs still face challenges.

Related Technologies

Because the responses returned by XMLHttpRequest are strings, XML is an ideal choice. X in Ajax indicates that XML will be accompanied by Ajax for life, because most developers have mastered this popular technology. For XML, it is necessary to understand Dom. XPath provides shortcuts for XML operations, while XSLT provides a natural breeding ground for HTML output. Therefore, the technologies mentioned must be mastered by Ajax developers. With the newly introduced XMLHTTPRequest object and more complex JavaScript code, I believe that technology learning will still suffer for a while.


Speaking of this, it is already a start for Ajax. I hope to provide some learning guidance to my new Ajax beginners. I am also a newbie.



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.