O Create Custom Dynamic Web Applications a Programmer Must Utilize Ajax. Ajax Is a Group
Total Page:16
File Type:pdf, Size:1020Kb
Ajax for Dynamic Web Development Gregory McChesney, Texas Tech-Computer Science
ABSTRACT These applications are usually slower because they require the server to process each request. O create custom dynamic web applications Most web applications require the entire Ta programmer must utilize Ajax. Ajax is a webpage to be processed at once. This means group of technologies that provide asynchronous when a user clicks on a link in a webpage the two-way communication between a server and whole page will be changed. With Ajax a user the web browser. Asynchronous communication can click on a link and have a section of the page allows the user to continue to browse the web recreated for them without changing the whole page as sections of it are being loaded. This also page. [6] This removes a portion of the load from allows the page to display new and updated the server because it only has to parse a section of the page rather than the whole page. information with out refreshing the page. [1] Ajax development has exploded in recent years as companies have found customers prefer pages developed with it. ESPN uses Ajax extensively ORGINS OF AJAX on their website to refresh scores and provide news headlines without the user having to update Even though Ajax wasn’t formally defined until February of 2005 the first Ajax type web the page. [2] Creating an Ajax request requires three application was released in 2000 by Microsoft sections of code, the first section is writing in for use with Outlook. Microsoft was looking to HTML, the second writing in JavaScript and the create a web based version of its popular email client that did not require the page to be third is a server script writing PHP. [3] Each section of code provides a different portion of refreshed to notify the user a new email had the Ajax request, if the request is missing any of arrived. [3] Microsoft created the XMLHttpRequest object which became the basis the sections it will fail. [3] While Ajax is good for many scenarios a programmer must carefully for Ajax traffic. [7] The XMLHttpRequest allows examine its use to prevent problems from a client computer to call a webpage in the arising. background without interfering with the user. [4] This type of transfer is called asynchronous because it passively waits for the server to INTRODUCTION respond. This is the first component in Ajax and is usually called thru JavaScript. [7] The technologies powering the internet are Using the XMLHttpRequest data can be changing at an accelerated rate; one of these gathered from the server. To update the webpage technologies is Ajax. Ajax or Asynchronous to show this new data Dynamic HTML must be JavaScript and XML are a group of technologies used. Dynamic HTML uses CSS, HTML and that provide a rich web development platform. JavaScript to rewrite sections of the webpage Jesse James Garrett introduced the term Ajax in code at the browser instead of regenerating the February of 2005 to describe a new method of page on the server. [8] programming using readily available The term Ajax became widely known after technologies. [5] Ajax requires four distinct the release of Google Maps and Google Suggest. components to provide a rich user interface. The [5] These products showed flexibility never before components are JavaScript, XML, HTML, and seen in a web application and thus spurred CSS. [5] developers to make new and innovative Ajax is unique because it allows for the applications. creation of desktop like applications in a web environment. Typically a “desktop” application AJAX EXAMPLE is very responsive and can have sections of the program change without refreshing the entire A trivial example of Ajax is a name retrieval screen. [6] This occurs because the program is service. The script will suggest names matching running on the local machine. Web applications the letters entered into the box without requiring usually run thru an internet browser like the page to be refreshed. If the script was written Microsoft Internet Explorer or Mozilla Firefox. without Ajax after each letter entered, the page
1 would need to be refreshed. This would create of code var xmlHttp. The three functions excess load on the web server and be distracting are showHint, stateChanged and
to the user. [9] GetXmlHttpObject. [9]
HTML CODE FUNCTION showHint()
Code Sample 1 shows the HTML code that The function showHint is the driver function generates the form. The code is standard of the JavaScript. The function takes the string hypertext markup language (HTML) with a few inputted in the form and creates the request to additions. The first addition is the clienthint.js the server. The function also tells the computer which holds the Ajax calls and declares a to call stateChanged when the request to the function called showHint(). To make the script server has completed. Function showHint is notify the user of new suggestions on each key shown in Code Sample 2. The first line of stroke the input section of the form has the showHint defines the variable xmlHttp as an following code added XmlHttpRequest by calling the onkeyup=”showHint(this.value)”. [6] This piece GetXMLHttpObject function. The second line of code makes the web browser call showHint defines a variable named url which contains the every time the user releases a key in the field. location of the server side script. Url is also The final portion of code required is this labels a section of parameter represents the string being sent to the the code as txtHint. [6] This label will be used server, the sid parameter is used only to make later to output the result of the Ajax query. [9] each request unique. [6] If the sid parameter was not given the web browser may not call the server script and use a cached copy instead. [9]
The next three lines setup the XmlHttpRequest parameters and perform the