ComputersProgramming

Ajax - what is this? Asynchronous JavaScript and XML: advantages and disadvantages

Now you can observe that the use and application of new technologies is gaining popularity on the Internet. One of them is AJAX. What it is? What characteristics does it have? Where is it applied? All of these questions can be answered within the framework of this article.

general information

How does AJAX decrypt? What does it mean? This abbreviation is an abbreviation. It stands for Asynchronous Javascript and XML ("Asynchronous Javascript and IKMLL"). You can often see or hear information that this is a new technology. But it is not so. The fact is that Javascript and XML have existed for quite a long time, whereas "Ajax" is a synthesis of these technologies. Most often it is used together with the term Web 2.0 and is meant as the use of advanced development methods.

And what is special about it?

So, we already have a general idea of what AJAX is. What does this give us in practice? Why are there active conversations about its application? The peculiarity of this technology is that when you use it, you do not need to update the whole page at the first need. After all, you can request new data only for part of it. This is convenient (because you have to wait less time), and economically (for those who do not have unlimited Internet). However, to inform the user about the update, it is desirable to use at least a download indicator or text messages that will inform about new data from the server. As a minus of technology is often mentioned the fact that it is not supported by obsolete and text-based browsers. Yes, and the ability to disable Javascript technology is the user, than many and use. Therefore, do not abuse AJAX. What can it do if you do not provide for alternative methods of presenting information? At best, the information will simply not be displayed on the site. At worst, its appearance will suffer so much that the user will not return to it any more.

Advantages of "Ajax"

This technology offers two methods by which a web page can be implemented. The first involves making changes without rebooting. This can be done with the help of dynamic calls to the server. The second involves the use of separate technologies, the most popular of which is XMLHttpRequest. Concerning the advantages of "Ajax" themselves, we can say the following:

  1. You can create a convenient web application, in which the interface will have a number of user-friendly features that will eventually facilitate the interaction of the person and the site.
  2. Instead of a full page reload, a partial reboot occurs. Thanks to this, the resources of the machine are saved and the speed is optimized.
  3. The server part of the site actively interacts with the user.
  4. It is convenient to use to implement a number of ideas.

Data exchange

Here, for example, we need a feedback form, through which it will be possible to advise clients. How can it be done? First, you need to take care of the "bearer" of information. To do this, create an XMLHttpRequest object. It acts as an intermediary between the server and the user's browser. With this object, queries will be sent, as well as answers to them. For direct data exchange we need AJAX PHP. This toolkit can be implemented using GET or POST requests. In this case, the necessary arguments will be passed directly through the URL. At the same time, a function will be launched to ensure that data transmission is not interrupted. But which AJAX request is implemented? Recommend using POST. Thanks to him, you can transfer an unlimited amount of data, which, moreover, is much more difficult to access.

Principle of operation

How does asynchronous Javascript and XML work in practice? Let's figure this out with an example. Concerning the structure of the building, care must be taken to ensure that the client part provides all the necessary functionality for secure data exchange. It must provide the necessary methods for transmitting information in selected ways. The server part should provide processing of the received data, and, based on them, generate new information in order to subsequently transfer it to the client. The most common interaction of this type is working with the database. Earlier, we already mentioned such an element of many business websites, as a form of feedback. The advantage of "Ajax" in this case is that it conducts asynchronous data transfer. In other words, while the information is being sent, the user can perform all the necessary actions. Focusing on the specifics of each specific case, it is necessary to decide whether it is necessary to inform the visitor of the site about this process. Concerning the same form of feedback, it should be said that in this case it is possible to write "an operator types an answer", or something similar.

Server Response

It can come not only through XML, as one might think because of the name of the technology. In addition, it can be passed as plain text or JSON. In the first case, the information received can be immediately displayed on the page. If XML is used, care must be taken to ensure that the AJAX file is properly processed in the client's browser. All data in this case is converted to (X) HTML. When the JSON format is used , you must execute the code to get a full Javascript object. It is necessary to be cautious and take into account the fact that many intruders like to transfer malicious code through this technology. Therefore, it is necessary to provide a procedure for checking the data received before processing them. The implementation features for different browsers may vary a little, but, in general, the scheme of the action is one.

We make a request to the server and process the response

The whole sequence of actions will look like this:

  1. Initially, you need to create and verify that there is XMLHttpRequest.
  2. Then, the connection to the server is initialized.
  3. We send a request to it.
  4. We wait until the data comes, and we process them.

It is necessary to tell about some features concerning creation of object. It can be initiated anywhere, wherever possible in the programming language. But if you assign it global status, then at any one time it will be possible for him to work with only one query. This moment is necessary to pay close attention. Concerning processing - here we are guided by the chosen tool. Thus, with XML, data must be processed by DOM functions and presented to the user already the final result in HTML. And what about JSON? It should be understood that it is an object notation for Javascript. What does it mean? Thanks to JSON, you can represent an object as a string. But it must be remembered that this method is not completely safe, and a lot of factors will need to be taken into account. But, in general, it is very easy.

Server Programming Languages

Virtually any web application uses them in one way or another. For data transfer, the most popular is PHP. It usually writes files for sites where the speed of information transfer is not critical, but gives priority to the balance between it and reliability. Methods for passing XMLHttpRequest were discussed above.

Configuring the server

What programs are needed to make AJAX work? What will it give us? What are they needed for? To get answers to these questions, please read the following list:

  1. HTML / XHTML. They are needed for the server to recognize the layout of the page.
  2. CSS. This tool is necessary for visual selection of page design.
  3. DOM. It is needed to provide dynamic changes to the page as a response to the action on the part of the user.
  4. XML. Required to transfer data between the client and the server.
  5. JavaScript. It is necessary to create the engine "Ajax" and provide interactivity.
  6. XMLHttpRequest. The object by which requests to the server will be forwarded.

Use on the site

So, now we have both theoretical knowledge and ideas about how AJAX works. Sending data now requires only a certain practice. Let's see in general how one can approach the implementation of the task with the use of "Ajax". So, we need to create a database of drivers. And they will differ in the devices on which they can work. It should be noted that the database in question is very large, so simply forwarding it to the client and already offering him to make a selection using JavaScript does not make sense. It is also not desirable that the web page itself be rebooted due to one parameter. On the server, requests will process special PHP scripts. The database is implemented as an XML file.

About the database

It is necessary to work out its structure. And what if the parameters that are objects are passed? In this case, it is necessary to provide creation of a variable where there will be a reference not to it, in the case of a call from the function side. To be able to access it from anywhere in the code, you need to make it global. For convenience, it is desirable to use a database management system. Of course, this is not necessary. But still using DBMS will allow you to work with data more conveniently and efficiently.

We are working on the work of the engine

How will everything happen? So, there comes a certain event, which will cause a special function. It will prepare GET or POST data that will be forwarded. Then, a function is called that will call the URL of the server script. It must provide for the creation of an XMLHttpRequest object. A reference to it should be stored in a variable. After the data has been sent to the server, it is necessary to wait for an answer from it. To do this, you can turn on the "wiretap" until information is received (if you know what will come and when) or provide a function that will always be ready to receive data. The first option is less reliable in the event of a freelance situation. The second implementation is more expensive in terms of resources. Although, if this is done only with respect to one variable, it will not affect the fast Internet. But if there are hundreds and thousands of them, and they will be large, then it will be another matter. Therefore, it is necessary to seek a balance between the use of available resources and efficiency. After all, it should be understood that not everyone has 16 GB of RAM. To do this, you can set a certain waiting time, after which the previous data is substituted or information that the server is not available at this time.

Features

When using "Ajax" interface for the page or application is created, it is necessary to make sure that the result obtained works well both on different operating systems and on different browsers. In the first case, emulators can provide invaluable help. In the second case, it will be sufficient to simply install various programs and check the code for them. It is also necessary to provide certain actions in case the user's browsers are obsolete or he will disable the necessary settings. In such cases, you should take care to display a page of text, which indicates the reason why viewing the site in this case is not possible. Yes, now the vast majority of people use modern technology, but do not completely ignore the likelihood and that a few percent of visitors will use a few obsolete software. And on a business scale this can have significant consequences.

Conclusion

So this article comes to a logical conclusion. If we talk about "Ajax" in general, then this tool allows you to create very attractive and multifunctional sites that work fast and with competent layout deliver their users a pleasure. We can not doubt that in the future there will be even more advanced technologies, but for now we will use what we have. As the programming languages and their methods are improved, it is also possible that such an option will become available that will allow the creation of an even better product. But anyway, it is necessary to work now with what is. And the name is "Ajax".

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.