Module 4

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

1.

Note on RIA

Rich Internet Applications (RIAs) stand at the forefront of modern web development, transcending
the limitations of conventional web applications. They are designed to offer users an experience akin
to traditional desktop applications, characterized by enhanced interactivity, dynamic content
delivery, and a visually compelling interface.

One of the hallmark features of RIAs is their adept utilization of asynchronous communication
methods. Technologies like AJAX enable seamless data exchange between the client and server,
allowing for real-time updates without the need for cumbersome page reloads. This asynchronous
nature is fundamental to providing a fluid and responsive user experience.

RIAs often boast sophisticated user interface elements, including interactive graphics, multimedia
components, and dynamic content delivery. This infusion of rich visuals contributes to a more
immersive and engaging interface, distinguishing RIAs from their static web application counterparts.

The technology landscape supporting RIAs is diverse. From Adobe Flash and Flex to modern
JavaScript frameworks like React, Angular, and Vue.js, developers have an array of tools to choose
from when creating these applications. HTML5, coupled with multimedia APIs, has also become a
foundational technology for building RIAs.

Beyond visual appeal, RIAs frequently incorporate client-side processing, distributing computational
tasks to the user's device. This not only contributes to enhanced responsiveness but also reduces the
load on servers, paving the way for a more scalable architecture.

In some cases, RIAs are designed to offer offline capabilities, allowing users to access certain features
even in the absence of an internet connection. This is achieved through local storage mechanisms
and intelligently managed caching strategies.

Responsive design principles are integral to RIAs, ensuring that these applications seamlessly adapt
to various screen sizes and resolutions. This adaptability enhances accessibility, enabling users to
interact with the application on devices ranging from desktops to tablets and smartphones.

In essence, Rich Internet Applications represent a fusion of cutting-edge technologies and design
principles aimed at delivering a transformative user experience. As the digital landscape continues to
evolve, RIAs remain at the forefront, driving innovation in web development and redefining
expectations for user interfaces on the internet.

2. Characteristics of RIA
A number of key features differentiate RIAs from traditional Web applications.

Direct interaction: In a traditional page-based Web application, interaction is limited to a


small group of standard controls: checkboxes, radio buttons and form fields. This severely
hampers the creation of usable and engaging applications. An RIA can use a wider range of
controls that allow greater efficiency and enhance the user experience. In RIAs, for example,
users can interact directly with page elements through editing or drag-and-drop tools. They
can also do things like pan across a map or other image.

Partial-page updating: Standard HTML-based Web pages are loaded once. If you update
something on a page, the change must be sent back to the server, which makes the changes
and then resends the entire page. There's no other way to do it with HTTP and HTML. With
traditional Web-based apps, network connectivity issues, processing limitations and other
problems require users to wait while the entire page reloads. Even with broadband
connections, wait times can be long and disruptive.

But RIAs incorporate additional technologies, such as real-time streaming, high-performance


client-side virtual machines, and local caching mechanisms that reduce latency (wait times)
and increase responsiveness. A number of commercial development tools (see below) permit
this partial-page updating.

Better feedback: Because of their ability to change parts of pages without reloading, RIAs can
provide the user with fast and accurate feedback, real-time confirmation of actions and
choices, and informative and detailed error messages.

Consistency of look and feel: With RIA tools, the user interface and experience with different
browsers and operating systems can be more carefully controlled and made consistent.

Offline use: When connectivity is unavailable, it might still be possible to use an RIA if the app
is designed to retain its state locally on the client machine. (Developments in Web standards
have also made it possible for some traditional Web applications to do that.)

Performance impact: Depending on the application and network characteristics, RIAs can
often perform better than traditional apps. In particular, applications that avoid round trips
to the server by processing locally on the client are likely to be noticeably faster. Offloading
such processing to the client machines can also improve server performance. The downside
is that small, embedded and mobile devices -- which are increasingly common -- may not
have the resources necessary to use such apps.

3. What is Ajax?

Ajax (Asynchronous JavaScript and XML):

Ajax, short for Asynchronous JavaScript and XML, is a web development technique used to create
dynamic and interactive user interfaces on web pages. It allows for asynchronous communication
between a web browser and a server, enabling parts of a web page to be updated without requiring
a full page reload. Ajax is not a specific technology or programming language; rather, it is a
combination of several existing technologies, including:

HTML (Hypertext Markup Language):

Defines the structure of web content and user interfaces.

CSS (Cascading Style Sheets):

Styles the layout and appearance of web pages.


JavaScript:

A scripting language that enables dynamic behavior on web pages.

XML (eXtensible Markup Language):

A markup language used for structuring data (though JSON is now more commonly used with Ajax).

Ajax allows for the creation of more responsive and interactive web applications by sending and
receiving data asynchronously between the browser and the server. The key features of Ajax include:

Asynchronous Requests:

Ajax enables web pages to send and receive data from the server asynchronously, meaning that the
rest of the page can continue to operate while the data is being exchanged in the background.

Partial Page Updates:

Instead of reloading the entire web page, Ajax allows specific parts of the page to be updated
dynamically. This results in a smoother and faster user experience.

Dynamic User Interfaces:

Ajax facilitates the creation of dynamic and interactive user interfaces by allowing real-time updates
and changes to content without requiring the user to navigate away or refresh the entire page.

Data Formats:

While XML was initially used for data exchange, JSON (JavaScript Object Notation) is now more
commonly employed due to its simplicity and ease of use.

XMLHttpRequest Object:

The XMLHttpRequest object is a core component of Ajax. It is used to send HTTP requests to the
server and handle the responses asynchronously.

Example of a simple Ajax request using JavaScript:

var xhr = new XMLHttpRequest();

xhr.open("GET", "https://api.example.com/data", true);

xhr.onreadystatechange = function() {

if (xhr.readyState == 4 && xhr.status == 200) {

// Handle the response here

console.log(xhr.responseText);

};

xhr.send();
4. Ajax design basics.

AJAX (Asynchronous JavaScript and XML) is a web development technique that allows for the
asynchronous exchange of data between the browser and the server. This enables web pages to
update dynamically without requiring a full page reload. Here are the basic principles and
components of AJAX design:

Asynchronous Requests:

The key feature of AJAX is its ability to make asynchronous requests to the server. This means that
the browser can send a request to the server and continue processing other tasks without waiting for
the response.

XMLHttpRequest Object:

The XMLHttpRequest object is a fundamental component of AJAX. It is used to interact with the
server by opening a connection, sending a request, and handling the response. While the name
suggests XML, modern applications often use other data formats like JSON.

var xhr = new XMLHttpRequest();

xhr.open("GET", "example.com/data", true);

xhr.onreadystatechange = function() {

if (xhr.readyState == 4 && xhr.status == 200) {

// Handle the response here

console.log(xhr.responseText);

};

xhr.send();

Callback Functions:

AJAX relies heavily on callback functions to handle responses. These functions are executed when the
asynchronous request completes. Developers typically define callback functions to update the user
interface or perform other actions based on the server's response.

Data Formats:

While XML was initially used for data exchange, JSON (JavaScript Object Notation) has become more
prevalent due to its simplicity and ease of use. JSON is a lightweight data interchange format that is
easy for humans to read and write and easy for machines to parse and generate.

Server-Side Processing:

On the server side, web applications must be configured to handle AJAX requests. The server
processes the request and sends back an appropriate response. This response can be HTML, XML,
JSON, or any other format depending on the application's requirements.

Security Considerations:
When using AJAX, it's crucial to consider security aspects such as Cross-Origin Resource Sharing
(CORS) to prevent unauthorized access to resources on different domains.

Error Handling:

Implement robust error handling to manage potential issues with AJAX requests. This includes
handling network errors, server errors, and other unexpected situations.

Libraries and Frameworks:

Many JavaScript libraries and frameworks simplify AJAX implementation. jQuery, for example,
provides a convenient API for making AJAX requests and handling responses.

$.ajax({

url: "example.com/data",

method: "GET",

success: function(data) {

// Handle the response here

console.log(data);

},

error: function(xhr, status, error) {

// Handle errors here

console.error(error);

});

5. Design patterns of Ajax

Local Event-Handling You want the user experience to be dynamic and responsive, but it slows things
down if you have to keep going to the server. THEREFORE, ensure most events are handled locally,
resorting to server-side interaction only when there is no local facility. To increase the cases where
local handling is sufficient, consider using Local Caches.

Local Cache You want to support Local Activity, but many events must be handled by resorting to data
on the server. THEREFORE, maintain a local cache of information. The cache might be created on
initialisation or accumulated after each query. When accumulating upon query, it’s probably
worthwhile performing a predictive download.

• Example: Websites have kept local information at hand for many years. Many forms cache a
mapping from countries to states, for instance. </span>

Predictive Download You want the application to respond quickly, but many user actions will require
information from the server. THEREFORE, anticipate likely user actions and pre-load the required
data. Note that this auxiliary information should ideally be downloaded after the main information
has been loaded. A “background thread” might even be used to continuously monitor the user’s local
behaviour, regularly pulling down information which might be useful.

• Example: Google Maps downloads more than you ask, evidenced by the fact that you can
move a little in each direction without forcing any new blocks to be loaded. Another way to
see this is to compare what happens when you pan slowly versus quickly. Another example
is International Herald Tribune, which caches entire articles to provide immediate
gratification when you click on “next page” (an example taken from here. Google asks the
browser to prefetch the first search result in case the user clicks on it. </span>

Submission Throttling You want the application to respond quickly, but it will be overloaded if the
server was accessed for every trivial input event. THEREFORE, instead of submitting upon each
Javascript event, use the events to change local state. Store events in a buffer variable, or some DOM
component, and frequently (e.g. once a second) poll to see if anything should be submitted. As a
variant to periodic polling, check the time since last submission whenever a new Javascript event
occurs. Note: If the period is long (e.g. 10 minutes), show the Synchronisation Status and consider
allowing explicit submission as well.

• Example: Instead of submitting upon keypress, Google Suggest uses setTimeout() to


periodically check if the input field has changed. </span>

Explicit Submission (An alternative to Submit Throttling.) You want the application to respond quickly,
but it will be overloaded if the server was accessed for every trivial input event. THEREFORE, instead
of submitting upon each Javascript event, require the user to explicitly request it, e.g. submit upom
clicking a button. Ensure the user knows what’s been submitted with Synchronisation Status.

• Example: Like many chat applications, the LiveChat demo requires you to click a “submit”
button in order to complete your chat message. </span>

Periodic Refresh You want the browser to be synchronised with the server, but information may
change server-side after the user last made a change (e.g. because of another user on the same
system). THEREFORE, the browser should periodically call the server so as to refresh any volatile
information. Furthermore, indicate information staleness is with Age Displays.

• Example: Open two browsers, and you’ll see that this chat demo polls the server for changes
every few seconds. </span>

Distinct URLs You want to let users send and bookmark information, but the application is dynamic
and the results of XMLHttpRequest interaction will not alter the URL. THEREFORE, use a URL-based
scheme or write distinct URLs whenever the input will cause a fresh new browser state, one that does
not depend on previous interaction.

• Example: A9 interacts via AJAX, but nevertheless provides a clean URL when you perform a
new search. Google Maps has a “Link to this Page” link, which will always provide a link to
whatever the user is looking at.</span>
6. Ajax VS traditional approach

7. Explain RUI implementation using Ajax with diagram.

Rich user interfaces can be achieved by using a combination of dynamic HTML elements such as
HTML and JavaScript. However, the scope of such an interface is limited to client-side behavior and
has minimal functional implications due to the lack of server-side interactions. The power of AJAX is
in its capability to provide even richer interface by supplementing its dynamic user interface with
powerful functionality through seamless server-side invocation power. AJAX allows individual user
interface components to communicate with the server and exchange data without the need for
refreshing the whole screen. This is achieved using a process called Web Remoting. Web remoting,
or the process of communicating between a browser and a server, can be performed in multiple ways.
The popular approaches that are supported by today's browsers are IFrames and XMLHttpRequest.
Dynamic HTML can be complemented with either of these methods to generate AJAX functionality.
Asynchronous JavaScript and XML or AJAX

Asynchronous communication between the client and the server forms the backbone of AJAX.
Although an asynchronous request-response method can provide signifi cant value in the
development of rich functionality by itself, the results are lot more pronounced when used in
conjunction with other functional standards such as CSS, DOM, JavaScript, and so on. The
predominant popularity of AJAX stems from such usage.

Client-server communication can be achieved either by using IFrames, or by using the supported
JavaScript function call XMLHttpRequest(). Due to certain limitations of IFrames, XMLHttpRequest
has gained a lot more acceptance. While IFrame can also be an effective option for implementing
AJAX-based solutions, in this chapter, we will focus largely on an XMLHttpRequest-based
implementation. The primary advantage of using AJAX-based interfaces is that the update of content
occurs without page refreshes. A typical AJAX implementation using XMLHttpRequest happens as
described in the following steps:

1. An action on the client side, whether this is a mouse click or a timed refresh, triggers a client event
2. An XMLHttpRequest object is created and confi gured
3. The XMLHttpRequest object makes a call
4. The request is processed by a server-side component
5. The component returns an XML (or an equivalent) document containing the result
6. The XMLHttpRequest object calls the callback() function and processes the result
7. The HTML DOM is updated with any resulting values

The following simplifi ed image illustrates the high-level steps involved in an AJAX request fl ow. The
portal client page gets served to the client browser, where the execution of JavaScript functions takes
place.

The following example illustrates the initialization of the request object and its basic use:

if (window.XMLHttpRequest) // Object of the current window {


// for non-IE browsers
request = new XMLHttpRequest();
}
else if (window.ActiveXObject){
// For IE
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.onreadystatechange = function()
{
// do something to process response
};
if (request.readyState == 4){
// everything received, OK. Do something now..
} else {
// wait for the response to come to ready state
}

8. J query framework with Ajax.

jQuery is a popular JavaScript library that simplifies many tasks related to DOM manipulation, event
handling, and asynchronous communication, particularly with Ajax. Using jQuery with Ajax makes it
easier to write concise and cross-browser-compatible code for making asynchronous requests and
handling responses. Here's an example of using jQuery for Ajax:

Including jQuery in your HTML document:

<!-- Include jQuery from a CDN (Content Delivery Network) -->

<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

Making a simple Ajax request with jQuery:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>jQuery Ajax Example</title>

<!-- Include jQuery from a CDN -->

<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>

</head>

<body>

<script>

// jQuery Ajax request

$.ajax({

url: 'https://api.example.com/data',

method: 'GET',
success: function(data) {

// Handle the successful response here

console.log(data);

},

error: function(xhr, status, error) {

// Handle errors here

console.error(error);

});

</script>

</body>

</html>

Explaining the code:

Include jQuery:

Include jQuery in your HTML document, either by downloading it and hosting it on your server or by
using a CDN (Content Delivery Network) link.

Ajax Request:

Use $.ajax() to make an Ajax request. Specify the URL, method (e.g., 'GET' or 'POST'), and define
success and error functions.

Success Callback:

The success callback function is executed if the Ajax request is successful. Handle the response data
within this function.

Error Callback:

The error callback function is executed if there is an error in the Ajax request. It provides information
about the error, such as the XMLHttpRequest object, status, and error message.

Using jQuery simplifies the process of making Ajax requests and handling responses, and it provides
a more concise syntax compared to vanilla JavaScript. However, keep in mind that with the
advancements in modern JavaScript and the introduction of the Fetch API, you might also consider
using native JavaScript for Ajax in newer projects.

You might also like