Showing posts with label AJAX. Show all posts
Showing posts with label AJAX. Show all posts

Monday, February 8, 2010

Who Benefits from AJAX?

AJAX offers benefits to both end users and developers. For end users, it reduces the “rich or reach” conflict; for developers, it helps in overcoming the constraints raised by HTTP.

Why End Users Want AJAX Applications

Users tend to view desktop applications as a sort of commitment. They install a program, usually from a disk pulled from a costly shrink-wrapped box. The program consumes hard disk space as well as a position in the program menu. The user may need to update the program periodically or perform an upgrade later on to get new features. If the program is proactive about updating itself, the user is confronted regularly with dialogs about accepting patches or downloads. In exchange for this investment of time, money, and energy, the user gets repaid by an application that is able to leverage the operating system and machine resources. It is a rich application. It has local storage capabilities, offers quick response times, and can present a compelling and intuitive graphical user interface.

More and more applications are accessible from the web browser, where the full resources of the hardware and OS are not available, but the user commitment of a desktop application is not required. Over the years, interacting with a web application has meant a predictable pattern for users. They click a link in the page and the browser flashes while the user waits until the screen is repainted (the dreaded post back). This cycle is repeated again and again. The user looks at what is presented on the page, interacts with it, and clicks somewhere. The browser produces an audible click for feedback and begins to post back to the server. The screen of the web browser flashes blank and some icon spins or flashes while the user waits for a new version of the page to be returned from the server. Many times, the new version of the page is almost exactly the same as the previous version, with only part of the page being updated. And then the cycle begins all over again. This has a sluggish feeling even when the user has a highspeed network connection.

The AJAX set of technologies has changed what users expect from web applications. JavaScript code running in the browser works to exchange data with the web server asynchronously. There is no click sound and the browser does not flash. The request to the server is nonblocking, which means the user is able to continue viewing the page and interacting with it. The script gets the updated data from the server and modifies the page dynamically using the DHTML coding methodology. The user is able to continue looking at the page while parts of it are updated in the background. AJAX is used to provide a more responsive experience, making web applications behave more like desktop installations. JavaScript is used to provide a richer experience with support for drag-and-drop, modal dialogs, and seemingly instantaneous updates to various parts of the page based on user inputs.

A big part of successfully leveraging AJAX technologies is in the perceived performance increase. Users appreciate web applications that anticipate their actions. If you also use JavaScript code in the background to pre-fetch images and data that may be needed, users can get a speedy response without the usual pause that accompanies their actions. Nobody wants to wait for data exchanges between client and server; studies have shown that a time lag between user input and subsequent UI changes can significantly reduce their productivity and give them the frustrating feeling that they are fighting the application. Users want web applications to behave like desktop installations but without the overhead associated with an installation. As more applications employ smart caching, anticipate user actions, and provide richer UI, the difference between web and desktop applications is becoming blurred. Expectations of web applications are rising. The end user has now seen that it is possible to avoid the commitment of installing a desktop application and still have a rich and responsive experience.

Why Developers Want AJAX

Often, the first question to arise when starting a new development project is what type of application it will be. Should it be a desktop application or a web application? This is a key decision because it has historically dictated a lot about the nature of the application and the development problem space. Many developers are now choosing to build web applications by default unless something about the application dictates that it must be a desktop install. If it must run offline or if it requires a user interface that is complex to achieve in HTML, targeting the web browser may be ruled out, and the choice to write a standalone application is forced.

Developers have a difficult job writing modern web applications due to the inherent worldwide-web functionality constraints imposed by the use of the Hypertext Transfer Protocol (HTTP) and the way browsers use it. HTTP is a stateless protocol. The web browser requests a page, possibly carrying some querystring or form input parameters, and the server processes the request and sends a response that includes HTML-rendered content. The server can only react to the information supplied in the current request and doesn’t know, based on the information in the request itself, details about the path the user took to get to the current view. When the response is rendered, the connection may be broken and the server won’t have any information to preserve for the next request. From the server’s perspective, it is simply listening for requests to come in from any browser anywhere and then reacting. The browser issues a request to the page and receives an HTML page in response. It uses the HTML it receives to render the user interface. The user interacts with the page, and, in response, the browser clears the screen and submits a new request to the server, carrying some information about user input or actions. Again, a complete HTML page is returned. The browser then presents the new version of HTML. Fundamentally, the HTTP protocol is stateless. The server gets a request and responds to it. The request carries limited information about the ongoing conversation that is happening between client and server.

AJAX makes this much better. AJAX breaks this pattern by updating portions of the page separately, via partial page rendering. Figure 1-1 shows a typical non-AJAX series of browser and server interactions. Each request results in a full page rendering, and, in response, the browser updates the user’s entire view.

In Figure 1-2, AJAX is employed to improve the user’s experience. A request is made for the initial page rendering. After that, asynchronous requests to the server are made. An asynchronous request is a background request to send or receive data in an entirely nonvisual manner. They are asynchronous because the user interface isn’t frozen during this time, and users can continue interacting with the page while the data transfer is taking place. These calls get just an incremental update for the page instead of getting an entirely new page. JavaScript running on the client reacts to the new data and updates various portions of the page, as desired. The number of requests to the server may be no different, or in some cases there may actually be more calls to the server, but the user perception is that the application feels more responsive. They aren’t forced to pause, even if it’s only a slight pause, and wait for the server while staring at a blank browser screen.

Almost a decade ago, the Microsoft Exchange Server team created an ActiveX control called XmlHttpRequest that could be instantiated from JavaScript and used to communicate with the server. This can occur without clearing the screen to paint a whole new page. Using the XmlHttpRequest object, you could send information to the server and get data back without requiring a whole new HTML page. JavaScript code could then manipulate the HTML dynamically on the client, avoiding the annoying flash and the wait that users associate with web browsing. This functionality was not limited to Internet Explorer for long. Soon, other browsers included XmlHttpRequest objects as well. Developers could now write richer applications with reach extending across various operating systems.

The browsers also created an advanced DOM (Document Object Model) to represent the browser, the window, the page, and the HTML elements it contained. The DOM exposed events and responded to input, allowing the page to be manipulated with script. Dynamic HTML (DHTML) opened the door to writing rich interfaces hosted within the web browser. Developers started writing hundreds and even thousands of lines of JavaScript code to make rich and compelling applications that would not require any client installation and could be accessed from any browser anywhere. Web applications began to move to a whole new level of richness. Without AJAX libraries, you would be faced with writing lots and lots of JavaScript code and debugging the sometimes subtle variations in different browsers to reach this new level of richness.

What Is ASP.NET AJAX?

ASP.NET AJAX is the name of Microsoft’s AJAX solution, and it refers to a set of client and server technologies that focus on improving web development with Visual Studio. Other companies have their own AJAX solution, often taking a radically different approach, but Microsoft has sought to build upon the popular ASP.NET technology by developing a comprehensive set of script libraries as well as server programming enhancements. One piece, the Microsoft AJAX Library, is a JavaScript library that works on a variety of browsers and serves to simplify JavaScript development. It provides you with the capability to easily write JavaScript using an object-oriented programming approach similar to code-behind programming in ASP.NET. You can use the functions of the Microsoft AJAX library to interact with the DOM, dynamically update portions of the page, communicate with the web server asynchronously, and write rich animations on the page. You’ll learn about the client features in Chapters 6 and 7, but for now think of the Microsoft AJAX Library as a type system and set of class libraries that simplify writing JavaScript to enhance the user experience, manipulate the DOM, and communicate with the web server. The huge benefit in using this library is that it abstracts the tedious low-level DHTML programming into an OOP model that is much easier to work with.

The other part of the ASP.NET AJAX release is the server-side ASP.NET 2.0 AJAX Extensions. These extensions build on top of the ASP.NET classes and controls and leverage the Microsoft AJAX Library sent to the browser. They make it easy to quickly take advantage of AJAX technologies to enrich an application. Through a set of standard web services, ASP.NET AJAX is also able to leverage server-based application services such as authentication and user profile storage. The extensions both extend some of the existing ASP.NET controls by adding new behaviors and include a new set of server controls that make it easy to do asynchronous updates to a page and leverage server resources.

The client and server pieces of ASP.NET are shown in Figure 1-3. ASP.NET is built on top of the Microsoft Internet Information Services (IIS) web server. ASP.NET AJAX builds on top of that and the web services it includes. The Microsoft AJAX Library runs in the browser to manipulate the DOM, communicate asynchronously with the web server, and take advantage of ASP.NET services.

The ASP.NET Component

The original (ASP) Active Server Pages technology was released as part of Internet Information Server 3.0. It was then improved with support for transactions and access to COM objects with the release of the NT 4.0 Option Pack almost ten years ago. At the time, most websites consisted of static HTML pages. To the extent that there were any dynamic applications, they were CGI (Common Gateway Interface) or ISAPI (Internet Server API) applications typically written in C and C++. With the release of Active Server Pages (ASP), developers could use JavaScript or VBScript on the server to leverage a set of intrinsic objects provided by ASP. “Classic ASP,” as it is now called, provided a session object so that developers didn’t need to worry about the stateless nature of HTTP. It had Request and Response objects that provided for easy access to data coming from forms on the client and a way to send updated information back. The Server and Application objects were an avenue for accessing information from the web server and utilizing a common set of COM objects across the application.

Although Classic ASP was a big win for developers, developers soon found that developing complex applications became difficult. The lack of support for modularization meant that applications ended up with such complex interdependencies in script that developers often referred to it as “spaghetti code.” Debugging support was severely lacking, and there were no rich design tools for developing applications. Performance also suffered because ASP used a slow scripting model, and syntax errors could only be detected at runtime. ASP.NET is a big leap forward. It provides compatibility for existing applications by including the same set of intrinsic objects found in Classic ASP but moves from interpreting JavaScript and VBScript on the fly to using a compiled set of pages and modules written in C# and VB.NET. Classic ASP simply executed script in order from the top to the bottom of the page; ASP.NET is an event-driven model with a page lifecycle, making it more like writing a desktop application. Now, instead of including separate JavaScript files to represent business objects, you can create objects in any .NET language and access them directly from ASP.NET.

ASP.NET takes a set of pages that contain code and markup and generates a Page class that is then compiled and cached. For each request to the page, the class is instantiated and a complete page lifecycle is executed. A set of events are executed, some of which have been overridden by the generated Page class. Controls in the page also participate in the lifecycle, databinding to backend databases, reacting to user input, and dealing with changes to their state from the user’s previous view. To react to user actions, the developer has only to provide an event handler for the given action. For example, the button control exposes a Click event. When using it, you don’t need to write code to examine all form variables on a page to know if the button was clicked. Instead, you just provide code for an event handler override. The event handler code can then update the HTML for the page or the properties and data of other controls on the page.

The JavaScript Component

AJAX technologies take advantage of the common support for JavaScript found in modern browsers. Because there is a standard that is supported across the various browsers, you can write scripts knowing that they will run. This wasn’t always the case.

In the mid 1990’s, Netscape and Microsoft (along with others) collaborated on a standard for a scripting language that they would support in their web browsers. The standard is called EcmaScript. Microsoft’s implementation is called JScript, but the language is generally referred to as JavaScript, as it was called in Netscape. (It has nothing to do with Java, but someone must have thought the association was useful for marketing purposes.) JavaScript program snippets are sent down to the browser along with the HTML, and they run inside the user’s browser to affect how the page is processed on the client.

JavaScript is not compiled; it is interpreted. There is no static type-checking like you get in C++ and C#. You can declare a variable without needing to specify a type, and the type to which the variable refers can change at any time. This makes it easy to get started programming in JavaScript, but there’s inevitably a certain amount of danger in allowing the data type of a variable to change dynamically at runtime. In the following snippet, notice that the variable can reference any type without difficulty:

var something = 1;
something = true;
something = “a string”;

JavaScript is a dynamic language. Types can actually be extended during program execution by other code. This means that you can write code that creates types on the fly. Because there is no enforcement of type safety, your code can receive these types as parameters or return values without any problem. This provides a great degree of flexibility and coding power.

The fundamental types in JavaScript are strings, numbers, Booleans, and functions. There is also support for objects and arrays, which are collections of the fundamental types. Some additional objects are included that are considered essential for many programming tasks. This includes support for regular expressions and date and time operations.

You can use the plus operator on strings in JavaScript to concatenate them:

var theEnd = “THE END.”;
var result = “Beginning, “ + “middle, and “ + theEnd;

In this example, the result variable is now the string: “Beginning, middle, and THE END.”

JavaScript interpreters use the IEEE floating-point standard for storing numbers. Ignoring the gory details, you can assume that for most programming tasks you won’t have any trouble.

The Boolean type in JavaScript is about what you would expect it to be but maybe not exactly so. The Boolean represents whether or not an expression is true, but it uses the C-style convention using integer values 0 and 1.

Variables can exist in JavaScript without having a value, and a variable may simply be undefined, which can produce unexpected results. In this piece of JavaScript, three variables are declared, and all of these comparisons are designed to return a true value.

You can check specifically to see if a variable has been defined like this:

if( typeof(undefinedVar ) == “undefined” )
{
alert(“undefinedVar is undefined”);
}

Variables can also have a null value, which is not the same thing as being undefined, as a null value does constitute a value.

Functions are also real types in JavaScript. They can accept arguments and return values. Functions can be passed to other functions and can be created dynamically by other script code.

Here are two equivalent definitions for a function called Add that will take two variables and return the result of applying the plus operator. Notice that I didn’t state that it takes two numbers. Remember, JavaScript variables don’t have a defined type, so I could just as easily pass two strings and get them concatenated by my Add function.

Once either of these styles is used to create a function, it can be called from that scope and any nested scope to perform the addition. There is no advantage to one of these forms over the other. You can simply choose to use the syntax that you prefer.

Objects and arrays are just collections of other types. Array types do not require that the values they hold be named; instead, you can access them by index. The values held in an object are referenced by field or property names. Objects can also hold functions (which can be accessor functions to give public visibility to local variables), which lets you create data structures that represent entities in JavaScript code. Missing from this sort of object-oriented programming is a concept of type inheritance. The Microsoft AJAX Library provides a set of classes and recommended patterns for achieving inheritance in JavaScript, making it more natural for switching between JavaScript and other high-level languages. The following code example includes a definition for an Album object that holds and returns the artist and album title. An array is then used to store information about several albums.

Packaging

The packaging of ASP.NET 2.0 AJAX can be fairly confusing. The basics of the packaging are:

  • ASP.NET 2.0 AJAX Extensions 1.0—The ASP.NET 2.0 AJAX Extensions 1.0, also referred to as the RTM/Core code, is an independent download. This contains the functionality that will receive support from Microsoft in the initial release of the product. The source code is available.
  • ASP.NET AJAX Futures Community Technology Preview (CTP) — The ASP.NET 2.0 AJAX framework contains a set of functionality that is experimental in nature. This functionality will eventually become integrated with the RTM/Core code. During the initial release, the Futures CTP functionality will be a separate download from the RTM/Core bits. This will not receive specific support from Microsoft beyond community-based support. The CTP bits require that the RTM/Core bits already be installed for the CTP bits to be installed. The CTP is also referred to as Value-Added Bits.
  • Microsoft AJAX Library—The Microsoft AJAX Library is a set of JavaScript client libraries that make up the standard download to a web browser and provide much of the support for AJAX in the client. These libraries will work with a non-IIS server and are available as a separate download. This library is included in the ASP.NET 2.0 AJAX Extensions 1.0 download as well as being available as a separate download.
  • ASP.NET AJAX Control Toolkit — The AJAX Control Toolkit is a separate download that provides a set of client-side GUI widgets that integrate with the ASP.NET 2.0 AJAX framework. The toolkit is licensed separately from the framework and includes the source code for developers who would like to review the source.

Futures

It has already been announced that ASP.NET 2.0 AJAX will be integrated into the .NET framework and Visual Studio in the Orcas versions of these products. Future versions will undoubtedly have more integration between ASP.NET 2.0 AJAX, ASP.NET, and Visual Studio.

Summary

AJAX provides developers a foundation to build web-based applications with an improved user experience. In this introductory chapter, you have looked at the following:

  • Development from a historical perspective
  • Web development methodologies
  • Some of the features that ASP.NET AJAX provides, such as improved user responsiveness and decreased load on the web server
  • Multiple technologies that can improve the user experience
  • The general components in the ASP.NET 2.0 AJAX packaging
  • The problems ASP.NET AJAX solves, and who is using it

Understanding AJAX

  • AJAX is an acronym for Asynchronous JavaScript and XML. If you think it doesn't say much, we agree. Simply put, AJAX can be read "empowered JavaScript", because it essentially offers a technique for client-side JavaScript to make background server calls and retrieve additional data as needed, updating certain portions of the page without causing full page reloads. Figure 1.4 offers a visual representation of what happens when a typical AJAX-enabled web page is requested by a visitor

What Is ASP.NET 2.0 AJAX?

On June 28, 2005, Microsoft announced “ASP.NET 2.0 AJAX.” ASP.NET 2.0 AJAX is an AJAX-oriented .NET library that runs on .NET 2.0. Though ASP.NET 2.0 AJAX is an AJAX library and can be used to perform AJAX operations, it is really much more. ASP.NET 2.0 AJAX offers many of the same types of features of the server-side ASP.NET, but it is directed at the client side. Because ASP.NET 2.0 AJAX is fully integrated with ASP.NET, it provides rich integration with the services provided by ASP.NET.

ASP.NET 2.0 AJAX provides the following features (and much more):

  • AJAX-style communications between client and server. This communication is over web services.
  • Asynchronous communication. All client-to-server communication in the ASP.NET 2.0 AJAX framework is asynchronous.
  • A set of server-side controls that enable rich client-side functionality.
  • A set of client-side controls and classes that further enable client-side functionality.
  • A framework for encapsulating client-logic through the creation of namespaces and classes.
  • Cross browser support. Although there is no official matrix of web browsers that ASP.NET 2.0 AJAX supports, the latest versions of Internet Explorer, Firefox, and Safari are supported. In addition, Opera is thought to be supported; however, we have not been able to find an official statement from Microsoft regarding this.

Running ASP.NET AJAX Applications

Unfortunately, not all web browsers ever produced will support ASP.NET AJAX. To run an ASP.NET AJAX application, a web browser must:

  • Be relatively modern — ASP.NET AJAX applications are not available in all versions of all web browsers. Though Internet Explorer version 6 and later, Firefox version 1.5 and later, and Safari provide support for these applications, older versions may be problematic because of their support for different versions of the other requirements.
  • Support the DOM — The capability to update form elements on a page based on new data is important. Accessing the controls in a standard way means that writing code that runs over a majority of web browsers is easier than having code that has a large number of if/then/else statements that are dependent on the browser version.
  • Support JavaScript — ASP.NET AJAX requires some amount of actions to occur out on the client. These actions are done using the JavaScript programming language. Because the major web browsers support JavaScript, it makes sense for JavaScript to be used for the client-side programming language.
  • Possibly have ActiveX enabled on the client — If you are using the Internet Explorer 6 browser while running on Windows, you may have problems if ActiveX is not enabled.

ASP.NET 2.0 AJAX falls into four areas:

Server-side controls — Server-side controls generate the appropriate client-side markup and script to perform client-side operations without the need for a postback. These controls provide a fairly easy environment to debug. For example, debugging with the UpdatePanel is fairly easy. Besides the UpdatePanel, other controls that work similarly are the ASP.NET AJAX Control Toolkit.

Client-side classes — These classes provide additional functionality to the client-side browser. This type of functionality is similar in concept to the base class libraries included in the .NET framework. An example would be the whole Sys.Net namespace along with the extensions to the base JavaScript objects.

Web services integration — This functionality allows a developer to use web services as the communication channel between the web browser and the web server without having to understand the differences between the MSXML component in IE and the XmlHttpRequest object in Firefox.

Technologies That Make Up AJAX

AJAX is a general umbrella term. AJAX itself stands for Asynchronous JavaScript And XML. The term was coined by Jesse James Garret of Adaptive Path in an essay published in February 2005 (http:// www.adaptivepath.com/publications/essays/archives/000385.php) and was quickly accepted by the development community.

Based on this general umbrella term, take a look at the specific items that make up AJAX:

  • XMLHttpRequest — XMLHttpRequest allows the browser to communicate to a back-end server. This object allows for the browser to talk to the server without requiring a postback of the entire web page. With Internet Explorer 5 and 6, this capability is provided by the MSXML ActiveX component. With the Mozilla Firefox, IE 7, and other web browsers, this capability is provided by an object literally called XmlHttpRequest. The XmlHttpRequest object is modeled after the MSXML component and defined by the XMLHttpRequest standard from the W3C. The ASP.NET 2.0 AJAX client-side JavaScript libraries hide the differences between the various browsers.
  • JavaScript—JavaScript provides the capability to communicate with the back-end server. The version of JavaScript must be version 1.5 or later. Though JavaScript is not specifically required, it is needed from the standpoint that JavaScript is the only client-side scripting environment supported across the major modern web browsers. There are other client script languages; however, these are not supported across all browsers.
  • DHTML/DOM support—The browser must support the ability to dynamically update form elements, and the ability to do this in a standard way comes through the support for the Document Object Model (DOM). By supporting the DOM, it becomes easy for developers to write a single piece of code that targets multiple browsers.
  • Data transport with XML or JSON — Using XML allows for the ability to communicate with the web server in a standard mechanism. The default data format with ASP.NET AJAX is JSON.

What Is AJAX?

So into this development environment comes a set of technologies that are collectively referred to as AJAX. If you are an “old guy” developer like me, then AJAX represents a similar concept to the client-server development mentioned earlier in the chapter. With client-server development, the amount of data transferred is minimized over a terminal application by transferring only the necessary data back and forth. Similarly, with AJAX, only the necessary data is transferred back and forth between the client and the web server. This minimizes the network utilization and processing on the client.

Advantages of AJAX

The advantages of AJAX over classical web-based applications include:

  • Asynchronous calls — AJAX allows for the ability to make asynchronous calls to a web server. This allows the client browser to avoid waiting for all data to arrive before allowing the user to act once more.
  • Minimal data transfer — By not performing a full postback and sending all form data to the server, network utilization is minimized and quicker operations occur. In sites and locations with restricted pipes for data transfer, this can greatly improve network performance.
  • Limited processing on the server — Along with the fact that only the necessary data is sent to the server, the server is not required to process all form elements. By sending only the necessary data, there is limited processing on the server. There is no need to process all form elements, process the ViewState, send images back to the client, or send a full page back to the client.
  • Responsiveness—Because AJAX applications are asynchronous on the client, they are perceived to be very responsive.
  • Context — With a full postback, users may lose the context of where they are. Users may be at the bottom of a page, hit the Submit button, and be redirected back to the top of the page. With AJAX there is no full postback. Clicking the Submit button in an application that uses AJAX will allow users to maintain their location. The user state is maintained, and the users are no longer required to scroll down to the location they were at before clicking Submit.

History of AJAX

For all its perceived newness and sexiness, the technologies that make up AJAX are really not new. The ability to communicate back to the server through a hidden frame without posting the main page back to the server has been around for a long time. Communication between client and server has been available— back to the release of Internet Explorer’s ability to script ActiveX controls on the client browser and to the MSXML component, both of which date back into the late 1990s. Personally, I saw the first formal usage of client script and MSXML in 2003. The problem with the technology at that time was the need to manually create the necessary client-side JavaScript. In 2003, there was too much code overall that had to be written and too much custom code that had to be written to get this to work. Only since the second half of 2005 have client-side libraries and server-side support for ASP.NET started to make their presence felt and been used significantly.

The mainstream development community has only recently started using the technique. The release of Google’s Suggest and Maps are what really opened the eyes of the users to the development technologies. These applications sent a shockwave through the development community.

Explain ASP.NET Ajax Framework.

Answer
ASP.NET Ajax Framework is used for implementing the Ajax functionality. It allows you to create interactive web applications which can update data on the web page without changing the actions of the existing page. The frame work includes both client and serer side components. The framework can be used best in ASP.NET 2.0.

Explain limitations of Ajax.

Answer

  • Back functionality cannot work because the dynamic pages don’t register themselves to the browsers history engine. Hence the need of Iframe becomes essential.
  • The page cannot be bookmarked if implemented using Ajax.
  • If java script is disabled , Ajax will not work
  • Because different components of the pages are loaded at different times, response time may be slow.
  • Because different components of the pages are loaded at different times it may create confusion for the user.

What is the role of Script Manager in Ajax?

Answer
Script Manager, as the name suggests is used to manage the client side script of Ajax. Since Ajax uses Java Script, there needs to be a mediator to manage this script and restrict a particular version to a browser. A Script manager is present on every page where Ajax is used to enable the Ajax Libraries. These Libraries in turn helps to implement the core Functionality of Ajax: Partial rendering.

List out differences between AJAX and JavaScript.

Answer
Ajax is Asynchronous Java Script and XML. Here on sending request to the server, one needn’t wait for the response. Other operations on the page can be carried out. Hence, Asynchronous. On the other hand, Java script sends an HTTPRequest to the server and waits for the XML response.

E.g. populating State field. Using JavaScript we need to use the “Onchnage” event where as using ajax, the request is just sent to populate the state list. Other operations can be carried out on the page.

Ajax is a part of Java Script programming. Java Script is used to manage and control a web page once downloaded. Ajax does not need to wait for the whole page to download.

Use of Ajax can reduce connections to the server since the script has to be requested once

Describe how to create AJAX objects.

Answer
Ajax Objects can be created by the following syntax:

Var ajax= New ajaxObject(‘page path’). Here page path is the URL you want the Object to call. The URL must be of the same domain as the webpage.

Define JSON.

Answer
JSON is JavaScript Object Notation. JSON is a safe and reliable data interchange format in JavaScript. This format is easy for humans to read and machines to understand.

Explain in brief abo XMLHttpRequest object.

Answer
XMLHttpRequest object is used to transfer data between a client and a server. Here the client can be a web browser. Here, the client can send and receive data without reloading the page.

It can be created as follow

Var request = new XMLHttpRequest ()

Describe the formats and protocols used by AJAX.

Answer

  • Ajax uses HTTP’s GET or POST. AJAX also uses XMLHttpRequest protocol for requesting to the web server.
  • AJAX uses JSON format to communicate between client and server. UED or URL encoded data formats can also be used.

What are the security issues with AJAX?

Answer
AJAX function calls are sent in plain text to server. These calls may easily reveal database details, variable names etc

User’s browsing session can be monitored my maliciously inserting scripts

Ajax may encourage developers to use multiple server side pages thereby introducing multiple entry points for attackers

Ajax security issues posted on March 12, 2009 at 22:35 pm by Rajmeet Ghai.

Are there any security issues with AJAX?

  • A JavaScript can not access the local file system without the user's permission.
  • An AJAX interaction can only be made with the servers-side component from which the page was loaded.
  • A proxy pattern could be used for AJAX interactions with external services.
  • The application model should not be exposed as some user might be able to reverse engineer the application.
  • HTTPS can be used to secure the connection when confidential information is being exchanged.

Describe how to handle concurrent AJAX requests.

Answer
JavaScipt closures can be used for handling concurrent requests. A function can be written to handle such requests. Once processing of code is over, URL and the call back function to call can be passed as parameters. These parameters are passed to the AJAXInteraction(url, callback) object. Closures insure that the proper callback function associated with a specific AJAX interaction is called.

When should AJAX NOT be used?

Answer

If the page is expected to be shown in a search engine like Google. Since Web crawlers don’t execute javascript code.

If the browser does not support JavaScript.

If security is a big concern in the application; Since Ajax allows end user to see half of what’s being sent to the server.

How do you know that an AJAX request has completed?

Answer
By determining the readyState property value of XMLHttpReqyest, One can know if the request is completed. If the readyState value = 4, the request has been completed and the data is available.

How do I handle the back and forward buttons?

Answer
In order to store changes in the browsers web history (enabling back and forward buttons) Iframes can be used. Iframes allow am HTML document to be embedded in another HTML document.

RSH (Really Simple History) framework can also be used. RSH framework explains the management of bookmarks and history for Ajax applications.

What is AJAX and what problem does it solve?

Answer
Ajax is a set of client side technologies that allows asynchronous communication between client and web server. In synchronous communication, complete round trip happens with each request/response action event when small data of the page to be refreshed. Ajax has solved this problem of posting entire information every time through asynchronous communication.

XmlHttpRequest is the basic fundamental behind Ajax. This allows browser to communicate with server without making post backs.

What are the benefits of AJAX over Java applet?

The following are the benefits of AJAX over Java applet:

  • AJAX applications are loaded in seconds, where as Applets takes longer time. The reason is, Applet applications are tend to load large libraries.
  • AJAX provides standard look and feel for web applications, where as Applets provides GUI based look and feel.
  • AJAX features can increase from a conventional web application, where as Applets uses complete programming process right from the scratch.
  • Java version changes enable incompatibilities between Applet and java environments used by the browser, where as in AJAX incompatibilities are not the constraints.

What is the disadvantage of AJAX?

The disadvantages of AJAX are:

  • Search engines would not be able to index an AJAX application.
  • The server information can not be accessed within AJAX.
  • AJAX is not well integrated with any browser.
  • ActiveX requests are enabled only in IE 5 and IE6
  • Data of all requests is URL-encoded, which increases the size of the request.

How is encoding handled in AJAX?

AJAX encoding can be done in two ways:

encodeActionURL() method is used for full page refresh
encodeResourceURL() method is used for partial page refresh.

Why is AJAX a comfortable fit with JAVA?

AJAX is a comfortable fit because, using Java Enterprise Edition the following tasks can be performed:

  • AJAX client pages can be generated to server incoming AJAX requests
  • Server side state is managed for AJAX clients
  • AJAX clients can be connected to enterprise resources.

What is synchronous request in AJAX?

Synchronous AJAX is a process that makes a java script to halt or stop the processing an application until a result is sent by a server. The browser is frozen, while the request is processed. The response time is 99.99% quick and fast enough. In case of intrusion for a request or transfer of the file, the browser freezes may be for two minutes until the time is out for the request. The advantages of using synchronous AJAX are, simple to code and can be used in the events ‘onunload’ and ‘onbeforeunload’

When should I use a Java applet instead of AJAX?

  • Applets provide features like custom data streaming, graphic manipulation, threading, and advanced GUIs which AJAX cannot.
  • However, with the help of DHTML, the functionalities of AJAX can be extended further.
  • AJAX requires that the browser be DHTML and AJAX capable.
  • AJAX-based functionality does need to take browser differences into consideration due to which using a JavaScript library such as Dojo which abstracts browser differences is recommended.
  • AJAX/DHTML works well for applications where the latest browsers are used.

How Ajax is different?

An AJAX application introduces a layer between the user and the server which comprises of the AJAX engine. This eliminates the adhoc interaction between the client and the server and makes the application more responsive.

A browser loads an AJAX engine instead of the web page and then communicates with the server on users behalf as well as provides the user with an interface.

As the communication with the server in AJAX is asynchronous, the user doesn’t have to wait for a server response.

Is the server or the client in control in AJAX?

With AJAX the control can be more centralized in a server-side component or a mix of client-side and server-side controllers.

  • Centralized server-side controller
    In this type of architecture, the controller ensures that the data on the client and the server are synchronized.
  • Client and server-side controllers
    In this type of architecture the presentation related control, event processing, page manipulation, and rendering of model data is done through Javascript on the client side.
    The server-side is responsible for business logic and pushing updated model data to the client.
    Both methods are viable depending on the kind of task. However, the centralized server side controller is preferred as in the other case (Client and server-side controllers) the server might not have the knowledge of the state of the client page.

Are there Usability Issues with AJAX?

The nature of updating a page dynamically using data retrieved via AJAX interactions and DHTML may result in drastically changing the appearance and state of a page.

Since the pages get updated dynamically, the state of a page may not remain the same.
So the behavior of a page may need to be defined in each of the following user actions:

  • Navigation using the back or forward buttons of the browser
  • Book-marking a page
  • Sharing a URL
  • Printing a page at any given time

Navigation:
The output of the user actions like a page refresh, forward or back navigation, etc need to be defined.
In this case using a JavaScript framework such as Dojo that provides API's history manipulation and navigation control would be simpler.

Book-marking and URL sharing:
Dojo provides client-side interface for book-marking and URL manipulation.

Printing:
Issues could arise while printing dynamically rendered pages.