Depending on how you want to use the object, different methods may become more important than others. This function can be handy if you are concerned about the length of the connection. If you only want a request to fire for a certain length of time, you can call the abort method to stop the request prematurely.
This method can be useful to retrieve one part of the generally large string obtained from a set of headers.
- Beginning Google Maps Applications With PHP And Ajax - PDF Drive.
- دانلود 90 کتاب مرجع آموزشی ای جکس - سون لرن.
- Frontier Woman (Sisters of the Lone Star);
- The Leopard.
- Innovations In GIS 5: Selected Papers From The Fifth National Conference On GIS Research UK!
For example, to retrieve the size of the document requested, you could simply call getResponseHeader "Content-Length". This is the method you use to open a connection to a particular file on the server. Keep in mind that not all of the arguments in this function are required and can be customized depending on the situation. An important note is that this method may only be invoked after the open method has been used, and must be used before the send function is called.
If the request was sent asynchronously, the response will come back immediately; if not, it will come back after the response is received. You can optionally specify an input string as an argument, which is helpful for processing forms, as it allows you to pass the values of form elements. XMLHttpRequest Properties Of course, any object has a complete set of properties that can be used and manipulated in order for it work to its fullest. It is important to take note of these properties — you will be making use of them as you move into the more advanced functionality of the object.
XMLHttpRequest Object Properties Property Description onreadystatechange readyState Used as an event handler for events that trigger upon state changes Contains the current state of the object 0: uninitialized, 1: loading, 2: loaded, 3: interactive, 4: complete responseText responseXML status Returns the response in string format Returns the response in proper XML format Returns the status of the request in numerical format regular page errors are returned, such as the number , which refers to a not found error statusText Returns the status of the request, but in string format e.
For example, if you have a function that handles some form of initialization, you could get the main set of functionality you want to fire as soon as the state changes to the complete state. This is a highly useful property for exception handling, and can be important when deciding when to perform certain actions. You can use this property to create individual actions based upon how far along the request is.
For example, you could have a set of code execute when readyState is loading, or stop executing when readyState is complete. If you are firing a request to a script of some sort, the output of the script will be returned through this property. With that in mind, most scripts will make use of this property by dumping it into an innerHTML property of an element, thereby asynchronously loading a script or document into a page element. For instance, if the file requested could not be found, the status will be set to because the file could not be found.
Where the status property might be set to , the statusText would return Not Found. By using both the status and statusText properties together, you can give your user more in-depth knowl- edge of what has occurred. After all, not many users understand the significance of the number Therefore, it is as important as ever to make sure your Ajax applications are cross- browser compatible.
One of the most important aspects of the Ajax functionality is that it can be deployed across browsers rather seamlessly, with only a small amount of work required to make it function across most browsers the exception being rather old ver- sions of the current browsers. Figure shows the difference between the Internet Explorer and non-Internet Explorer outcomes. This script lets you know which browser you are currently using to perform an Ajax-based request.
- Web Mapping!
- Olefin Metathesis: Theory and Practice!
- From Novice to Professional.
- Introduction to the Theory of Atomic Spectra?
- Beginning Google Maps Applications with PHP and Ajax: From Novice to Professional.
- 5 editions of this work!
- Beginning Google Maps Applications with PHP and Ajax From Novice to Professional - Tài liệu text.
- Opportunities in Chiropractic Careers, 2nd Edition;
Basically, it checks whether the user is using a newer version of Internet Explorer by attempting to create the ActiveX Object ; if not, the script will default to the older ActiveX Object. Now, it is important to keep in mind that this method of initiating an XMLHttpRequest object is not the only way to do so. Unfortunately, while it does the job, I feel it is less thorough, and since you are going to be making use of some object-oriented technologies, it makes sense to use the first example for your coding.
A large part of using Ajax is making sure you take care of as many cases as possible. Sending a Request to the Server Now that you have your shiny, new XMLtlttpRequest object ready for use, the natural next step is to use it to submit a request to the server. This can be done in a number of ways, but the key aspect to remember is that you must validate for a proper response, and you must decide whether to use the GET or POST method to do so.
It should be noted that if you are using Ajax to retrieve information from the server, the GET method is likely the way to go. If you are sending information to the server, POST is the best way to handle this.
Beginning Google Maps Applications with PHP and Ajax From Novice to Professional PHẦN 6 ppt
In order to make a request to the server, you need to confirm a few basic functionality- based questions. First off, you need to decide what page or script you want to connect to, and then what area to load the page or script into.
Consider the following function, which receives as arguments the page or script that you want to load and the div or other object that you want to load the content into. It then attempts to open a connection to the server page using the open method of the XMLHttpRequest object. If the readyState property returns a 4 complete code and the status property returns a OK code, then you can load the response from the requested page or script into the innerHTML element of the passed-in object after you send the request.
Basically, what is accomplished here is a means to create a new XMLHttpRequest object and then use it to fire a script or page and load it into the appropriate element on the page. Now you can begin thinking of new and exciting ways to use this extremely simple concept. Basic Ajax Example As Ajax becomes an increasingly widely used and available technique, one of the more common uses for it is navigation. It is a rather straightforward process to dynamically load content into a page via the Ajax method.
Series: The Expert's Voice in Web Development
However, since Ajax loads in the content exactly where you ask it to, without refreshing the page, it is important to note exactly where you are loading content. With Ajax, however, if you scroll down on a page and dynamically load content in with Ajax, it will not move you back to the top of the page. The page will sit exactly where it is and load the content in without much notification. Therefore, if Ajax is to be used as a navigational tool, it is important to note that not all page layouts will react well to such functionality. In my experience, pages that rely upon navigational menus on the top of the screen rather than at the bottom, in the content, or on the sides and then load in content below it seem to function the best, as content is quite visible and obvious to the user.
Consider the following example, which shows a generic web page that loads in con- tent via Ajax to display different information based on the link that has been clicked. Ut enim ad minim veniam, quis nostrud exercitation ullamco laborls nisi ut aliquip ex ea commodo consequat. You can call the makerequest function on any event you are using onclickQ here to load content into the respective object that is passed to the function.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Figure An Ajax-based application in full effect. Note the address bar, which shows whether you have refreshed the page as you navigate. Because the design wrapper only needs to be created once and content can be loaded on the fly , users will find less lag when viewing the web site, and have a seamless page in front of them at all times. Using the Ajax method allows the content being retrieved from the server to be loaded with little to no obtrusive maneuvering of the web page that the user is viewing.
Summary To summarize, Ajax can efficiently produce seamless requests to the server while retriev- ing and manipulating both external scripts and internal content on the fly. It is quite simple to set up, very easy to maintain, and quite portable across platforms.
A Google-Map-Based Arterial Traffic Information System - Semantic Scholar
Throughout this chapter, I will run through some examples of how PHP and Ajax can be used together to design some basic tools that are quite new to Internet applications but have been accessible to desktop applications for ages. The ability to make a call to the server without a page refresh is one that is quite powerful, if harnessed correctly.
With the help of the powerful PHP server-side language, you can create some handy little applica- tions that can be easily integrated into any web project. Why PHP and Ajax?