Professional Documents
Culture Documents
IP IA-2 Answers
IP IA-2 Answers
Responsive User Interface: RIAs are known for their ability to provide
a responsive and dynamic user interface. They can update and render
content on the client-side without requiring a full page reload,
resul�ng in a smoother and more interac�ve user experience.
Client-Side: This is the user's web browser, where the user interacts
with the web applica�on. JavaScript plays a central role in AJAX, as it
handles the asynchronous requests and updates the user interface.
(Diagram)
Q3. What is AJAX? Explain AJAX web applica�on model with neat
diagram.
Ans. AJAX (Asynchronous JavaScript and XML) is a web development
technique used to create interac�ve and responsive web
applica�ons. It allows web pages to exchange data with a web server
asynchronously, without requiring a full page reload. This results in a
smoother and more interac�ve user experience, as users can interact
with the web applica�on while data is fetched or sent in the
background.
(Diagram)
Q4. Write AJAX code to read from the text file and displaying it a�er
clicking of a buton
Ans. <!DOCTYPE html>
<html>
<head>
<�tle>AJAX Text File Reader</�tle>
</head>
<body>
<h1>Click the buton to load and display text from a file</h1>
<buton id="loadButon">Load Text</buton>
<div id="textContainer"></div>
<script>
document.getElementById('loadButon').addEventListener('click',
func�on () {
loadTextFile();
});
func�on loadTextFile() {
var xhr = new XMLHtpRequest();
xhr.open('GET', 'tex�ile.txt', true);
xhr.onload = func�on () {
if (xhr.status === 200) {
var textContainer =
document.getElementById('textContainer');
textContainer.innerHTML = xhr.responseText;
}
};
xhr.send();
}
</script>
</body>
</html>
Q5. What is Single page applica�on? Explain React JSX with suitable
examples such as rendering the gree�ng message “Hello! Welcome
to React.”
Ans. A Single Page Applica�on (SPA) is a web applica�on or website
that interacts with the user by dynamically rewri�ng the current web
page rather than loading en�re new pages from the server. In a
tradi�onal mul�-page applica�on, when you click on a link or
perform an ac�on, the browser requests a new page from the server,
and the en�re page is reloaded. In contrast, SPAs load a single HTML
page and dynamically update the content as the user interacts with
the applica�on. This approach provides a smoother, more responsive
user experience, as only the necessary data is fetched from the
server, reducing the need to reload the en�re page.
Code:
import React from 'react';
import ReactDOM from 'react-dom';
func�on Gree�ng() {
return (
<div>
<h1>Hello! Welcome to React</h1>
</div>
);
}
Code:
import React from 'react';
func�on MyComponent() {
return (
<div>
<h1 className="header">Hello, JSX!</h1>
<p style={{ color: 'blue', fontSize: '16px' }}>This is a JSX
example.</p>
</div>
);
}
export default MyComponent;
State and Props: React components can have both state and props.
State represents a component's internal data, which can change over
�me. Props, short for proper�es, are used to pass data from a parent
component to its children.
<div id="xmlOutput">
<h2>XML Representa�on:</h2>
<pre id="xmlText"></pre>
</div>
<script>
func�on generateXML() {
const productId =
document.getElementById("productId").value;
const productName =
document.getElementById("productName").value;
const productCost =
document.getElementById("productCost").value;
const purchaseDate =
document.getElementById("purchaseDate").value;
document.getElementById("xmlText").textContent = xml;
}
</script>
</body>
</html>
Q9. Write down source code to create database and retrieve data
with connec�on of PHP.
Ans. <?php
$hostname = 'localhost';
$username = 'your_username';
$password = 'your_password';
$database = 'mydatabase';
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "ID: " . $row['id'] . " - Name: " . $row['name'] . " - Email: " .
$row['email'] . "<br>";
}
} else {
echo "No results found";
}
$conn->close();
?>
Q10. Explain the features of PHP and write a PHP program to print
factorial of a number.
Ans. PHP (Hypertext Preprocessor) is a widely-used open-source
scrip�ng language that is primarily designed for web development. It
has several features that make it a popular choice for web
developers:
Code:
<!DOCTYPE html>
<html>
<head>
<�tle>Factorial Calculator</�tle>
</head>
<body>
<h2>Factorial Calculator</h2>
<?php
func�on factorial($n) {
if ($n <= 1) {
return 1;
} else {
return $n * factorial($n - 1);
}
}
if (isset($_POST['calculate'])) {
$result = factorial($number);
echo "The factorial of $number is $result";
}
?>
<form method="post" ac�on="">
Enter a number: <input type="number" name="number"
value="<?php echo $number; ?>">
<input type="submit" name="calculate" value="Calculate">
</form>
</body>
</html>