Module 5
Module 5
Ajax, which is not a technology in itself, but something overlaid on top of other
technologies
Ajax is a way of using client-side technologies to talk with a server and perform partial
page updates.
The concept of "partial page updates" using Ajax to just load the change would be faster
than reloading the entire page for every minor change in web applications
Ajax which allows web pages to update asynchronously by exchanging data to and from the
server.
This means you can update parts of a web page without reloading the complete web page.
It involves a combination of a browser built-in XMLHttpRequest object, JavaScript, and
HTML DOM.
•A browser built-in XMLHttpRequest object (to request data from a web server)
•JavaScript and HTML DOM (to display or use the data)
•AJAX applications might use XML to transport data, but it is equally common to transport data
as plain text or JSON text
How AJAX Works
1.An event occurs on a web page, such as an initial page load, form submission, link or button click, etc.
2.An XMLHttpRequest object is created and sends the request to the server .
3.The server responds to the request.
4.The response is captured and then server respond back with response data.
There are many scenarios to make GET and POST requests to load and post data from the server asynchronously,
this enables web applications to be more dynamic and reduces page load time.
JavaScript
What is JavaScript?
JavaScript is a versatile, high-level programming language primarily used to create interactive
effects within web browsers.
It's an essential part of web development alongside HTML and CSS.
JavaScript is a scripting or programming language that allows you to implement complex
features on web pages
Ajax running JavaScript as its engine
application will have JavaScript working with XMLHttpRequest,
JavaScript working with HTML, XHTML, or HTML5;
JavaScript working with CSS, XML or JSON, DOM,
Key Features of JavaScript
•Event Handling: Responds to user interactions like clicks, form submissions, and mouse movements.
•DOM Manipulation: Allows dynamic changes to the HTML structure and styling of web pages.
•Asynchronous Programming: Manages tasks like API calls without blocking the main thread using promises,
async/await, and callbacks.
•Data Types: Includes numbers, strings, booleans, objects, arrays, and more.
•Functions: Supports first-class functions, closures, and arrow functions
XMLHttpRequest.onreadystatechange, which is called without argument each time the ready state of
XMLHttpRequest changes
HTML (Hyper Text Markup Language) is used to create web pages and web applications.
HTML's primary purpose is to display content, given in a text-based document,
XML allows different applications to exchange and store data , XML supports information
exchange between computer systems such as websites, databases, and third-party
applications.
XML Does Not Use Predefined Tags
HTML works with predefined tags like <p>, <h1>, <table>, etc.
<!DOCTYPE html>
<html>
<head>
<title>GeeksforGeeks</title>
</head>
<body>
<h1 style="color: green;">
GeeksforGeeks
</h1>
<p>
A Computer Science portal for geeks
</p>
</body>
</html>
Example
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Example
In JSON, string values must be written with double quotes:
JSON
{"name":"John"}
In JavaScript, We can write string values with double or single quotes:
JavaScript
{name:'John'}
The DOM
What is DOM?
DOM, or Document Object Model, is a programming interface that represents structured documents like
HTML and XML as a tree of objects.
It defines how to access, manipulate, and modify document elements using scripting languages like JavaScript.
getElementsByName() Returns all the elements having the given name value.
getElementsByTagName() Returns all the elements having the given tag name.
getElementsByClassName() Returns all the elements having the given class name.
iframes and other Ajax variations
iframes, or inline frames, are HTML elements used to embed another HTML document
within a webpage.
They allow to display content like videos, maps, or other web pages inside your page
Example
<iframe src="https://www.example.com" width="600" height="400"></iframe>
Key Attributes:
Basic Concept
Steps
1. AJAX Call: Use JavaScript (often with libraries like jQuery) to make an AJAX request.
2. Modify Iframe: Use JavaScript to change the src attribute of the iframe or directly
insert content.
jQuery and Basic AJAX
$.ajax()
Context
Closures