0% found this document useful (0 votes)
2 views

WEB TECHNOLOGIES-2-1

The document contains questions and answers related to web technologies, including PHP, JavaScript, AJAX, and XML. It covers topics such as error handling, form validation, session management, MVC architecture, and jQuery selectors. Additionally, it provides examples of code for various functionalities like AJAX search and jQuery manipulation.

Uploaded by

pravinalte12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

WEB TECHNOLOGIES-2-1

The document contains questions and answers related to web technologies, including PHP, JavaScript, AJAX, and XML. It covers topics such as error handling, form validation, session management, MVC architecture, and jQuery selectors. Additionally, it provides examples of code for various functionalities like AJAX search and jQuery manipulation.

Uploaded by

pravinalte12
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

WEB TECHNOLOGIES – II-1

Q1) Attempt any EIGHT of the following: [1 Mark each]


a) Which function is used to print an error message and exit
from current code? The die() function in PHP is used to print
an error message and exit from the current script.
b) What is sticky form? A sticky form is a form that retains
user input values after submission. If there are validation
errors, the form will redisplay with the user's previously
entered data, preventing them from having to re-enter all the
information.
c) XML Parser cannot alter documents or create new
documents. Justify True or False. True. XML parsers are
designed to read and interpret XML documents, but they do
not have the capability to alter or create new documents.
d) What is DOM? The Document Object Model (DOM) is a
programming interface for web documents. It represents the
structure of a document as a tree of objects, allowing
programs and scripts to dynamically access and update the
content, structure, and style of the document.
e) How are variables declared in JavaScript? Variables in
JavaScript can be declared using var, let, or const keywords.
javascript
var x = 10;
let y = 20;
const z = 30;
f) What is JQuery? jQuery is a fast, small, and feature-rich
JavaScript library designed to simplify HTML DOM tree
traversal and manipulation, as well as event handling, CSS
animation, and Ajax.
g) Give any two applications of AJAX.
1. Auto-complete search: Enhances user experience by
providing search suggestions as the user types.
2. Real-time data updates: Refreshes parts of a web page
without reloading the entire page, such as updating a
live sports score.
h) Which object is used to make web pages interactive in
AJAX? The XMLHttpRequest object is used in AJAX to make
asynchronous calls to the server.
i) What is CodeIgniter? CodeIgniter is an open-source web
application framework for PHP. It is designed to help
developers build dynamic websites quickly with minimal
configuration.
j) Which function is used for page redirecting? The header()
function in PHP is used to redirect users to a different page.
php
header("Location: http://www.example.com");
exit();
Q2) Attempt any FOUR of the following: [2 Marks each]
a) Discuss differences between GET and POST method.
1. GET:
o Parameters are sent in the URL.
o Limited amount of data can be sent.
o Not secure for sensitive information.
o Can be bookmarked.
o Used for retrieving data.
2. POST:
o Parameters are sent in the request body.
o Large amounts of data can be sent.
o More secure for sensitive information.
o Cannot be bookmarked.
o Used for submitting data.
b) Explain any five elements of $_SERVER variable.
1. $_SERVER['PHP_SELF']: Returns the filename of the
currently executing script.
2. $_SERVER['SERVER_NAME']: Returns the name of the
host server.
3. $_SERVER['HTTP_USER_AGENT']: Returns the user agent
string of the browser.
4. $_SERVER['REQUEST_METHOD']: Returns the request
method used to access the page (e.g., POST, GET).
5. $_SERVER['REMOTE_ADDR']: Returns the IP address
from where the user is viewing the current page.
c) Explain the concept of session handling with example.
Session handling is used to store user data across multiple
pages. In PHP, sessions are started using session_start(), and
data is stored in the $_SESSION superglobal array.
Example:
php
// Start the session
session_start();

// Set session variables


$_SESSION["username"] = "JohnDoe";
$_SESSION["email"] = "[email protected]";

// Access session variables


echo "Username: " . $_SESSION["username"];
echo "Email: " . $_SESSION["email"];
d) Explain the structure of a well-formed XML document. A
well-formed XML document adheres to XML syntax rules:
1. Declaration: The XML declaration is optional but should
be at the top.
xml
<?xml version="1.0" encoding="UTF-8"?>
2. Root Element: A single root element that contains all
other elements.
xml
<root>
<child>Content</child>
</root>
3. Matching Tags: Every start tag must have a
corresponding end tag.
xml
<element>Value</element>
4. Nesting: Elements must be properly nested.
xml
<parent>
<child>Content</child>
</parent>
5. Case Sensitivity: XML tags are case-sensitive.
xml
<item>Value</item> <!-- Correct -->
<Item>Value</Item> <!-- Incorrect -->
e) Draw and explain AJAX web application module. AJAX
Web Application Module:
plaintext
User Interface (Browser)
|
V
JavaScript (AJAX)
|
V
XMLHttpRequest (Client-side)
|
V
Web Server
|
V
Server-side Script (e.g., PHP)
|
V
Database
Explanation:
• User Interface: The user interacts with the web page.
• JavaScript (AJAX): JavaScript code makes asynchronous
requests using AJAX.
• XMLHttpRequest: Object used to send and receive data
from the web server.
• Web Server: Receives the request and processes it.
• Server-side Script: Executes the server-side logic (e.g.,
fetching data from the database).
• Database: Stores and retrieves data as requested by the
server-side script.
Q3) Attempt any TWO of the following: [4 Marks each]
a) Explain the workflow of MVC Architecture. MVC
Architecture:
• Model: Manages the data and business logic. It interacts
with the database and processes the data.
• View: Displays the data provided by the Model in a user-
friendly format. It represents the UI.
• Controller: Handles the user input and updates the
Model and View accordingly. It acts as an intermediary
between Model and View.
Workflow:
1. User interacts with the View (UI).
2. Controller receives the user input from the View.
3. Controller requests data from the Model.
4. Model retrieves data from the database and processes
it.
5. Model sends the data back to the Controller.
6. Controller updates the View with the new data.
Diagram:
plaintext
User
|
View <--> Controller <--> Model
|
Database
b) Which are the fields used in cookies?
1. Name: The name of the cookie.
2. Value: The value stored in the cookie.
3. Domain: The domain for which the cookie is valid.
4. Path: The path within the domain where the cookie is
valid.
5. Expiration: The expiration date of the cookie.
6. Secure: Indicates if the cookie should only be
transmitted over secure protocols (e.g., HTTPS).
7. HttpOnly: Indicates if the cookie is accessible only
through the HTTP protocol and not via JavaScript.
c) What is XML parser? Explain it with its types. An XML
parser is a tool that reads XML documents and provides
access to their content and structure. It checks for well-
formedness and validity.
Types:
1. DOM Parser: Loads the entire XML document into
memory and represents it as a tree of objects. Allows for
manipulation of the document.
o Example: JavaScript's DOMParser class.
2. SAX Parser: Parses the XML document sequentially. It
doesn't load the entire document into memory and is
event-driven. Suitable for large XML documents.
o Example: Python's xml.sax module.
Q4) Attempt any TWO of the following: [4 Marks each]
a) Write a JavaScript code to display message - ‘Exams are
near, Prepare well for it’ using alert, prompt and confirm
boxes. Accept proper input from user and display messages
accordingly.
javascript
// Alert box
alert('Exams are near, Prepare well for it');

// Prompt box
let name = prompt('Enter your name:');
if (name !== null) {
alert('Hello, ' + name + '! Get ready for your exams.');
}

// Confirm box
let confirmation = confirm('Do you want to start your
preparation now?');
if (confirmation) {
alert('Great! Let\'s get started, ' + name + '!');
} else {
alert('Okay, don\'t delay too much, ' + name + '.');
}
b) Write a PHP program to add or append in paragraph text
and also in the numbered (ordered) list in a given HTML
document using jQuery selectors.
php
<!DOCTYPE html>
<html>
<head>
<title>jQuery Append</title>
<script src="https://code.jquery.com/jquery-
3.6.0.min.js"></script>
<script>
$(document).ready(function(){
// Append text to a paragraph
$('#appendTextBtn').click(function(){
$('p#paragraph').append(' Exams are approaching,
prepare well!');
});
// Append new list item to an ordered list
$('#appendListBtn').click(function(){
$('ol#orderedList').append('<li>Start studying for
exams!</li>');
});
});
</script>
</head>
<body>

<h1>jQuery Append Example</h1>

<p id="paragraph">This is a paragraph.</p>


<ol id="orderedList">
<li>Buy study materials</li>
<li>Review notes</li>
<li>Practice problems</li>
</ol>

<button id="appendTextBtn">Append Text to


Paragraph</button>
<button id="appendListBtn">Append Item to List</button>
</body>
</html>
This script uses jQuery to append text to a paragraph and a
new list item to an ordered list when the respective buttons
are clicked.
c) Write an Ajax program to search Student Name according
to the character typed and display list using an array.
Here’s an example using Ajax to search for student names:
php
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<title>AJAX Student Search</title>
<script src="https://code.jquery.com/jquery-
3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$('#searchInput').on('input', function(){
var query = $(this).val();
if (query !== '') {
$.ajax({
url: "search.php",
method: "POST",
data: {query: query},
success: function(data) {
$('#result').html(data);
}
});
} else {
$('#result').html('');
}
});
});
</script>
</head>
<body>

<h1>Student Name Search</h1>


<input type="text" id="searchInput" placeholder="Type a
name...">
<div id="result"></div>

</body>
</html>
php
<!-- search.php -->
<?php
if (isset($_POST['query'])) {
$query = $_POST['query'];
$students = array("John", "Jane", "Jack", "Jill", "Jessica",
"James");
$output = '<ul>';
foreach ($students as $student) {
if (stripos($student, $query) !== false) {
$output .= '<li>' . $student . '</li>';
}
}
$output .= '</ul>';
echo $output;
}
?>
This example includes a simple HTML interface and a PHP
script. The HTML file contains an input field where users can
type a name. The script sends the input to the search.php file
using Ajax, which searches for matching student names in the
array and returns the results.
Q5) Attempt any one of the following: [3 Marks each]
a) Write XML syntax rules.
• XML Declaration: The declaration should be at the
beginning of the document.
xml
<?xml version="1.0" encoding="UTF-8"?>
• Single Root Element: There must be one and only one
root element that contains all other elements.
xml
<root></root>
• Case Sensitivity: XML tags are case-sensitive.
xml
<Item></Item> <!-- Correct -->
<item></item> <!-- Incorrect if case doesn't match -->
• Proper Nesting: Elements must be properly nested.
xml
<parent>
<child></child>
</parent>
• Attribute Values in Quotes: Attribute values must be
enclosed in quotes.
xml
<element attribute="value"></element>
• Closing Tags: Every element must have a closing tag.
xml
<element></element>
b) What are jQuery selectors? Explain in brief. jQuery
selectors are used to select and manipulate HTML elements.
They are based on CSS selectors and allow you to find and
select HTML elements based on their id, class, tag, attribute,
and more.
• Element Selector: Selects all elements of a specified
type.
javascript
$("p") // Selects all <p> elements
• ID Selector: Selects a single element with a specific ID.
javascript
$("#myId") // Selects the element with ID 'myId'
• Class Selector: Selects all elements with a specific class.
javascript
$(".myClass") // Selects all elements with class 'myClass'
• Attribute Selector: Selects elements with a specified
attribute.
javascript
$("input[type='text']") // Selects all <input> elements with
type 'text'
• Descendant Selector: Selects elements that are
descendants of a specified element.
javascript
$("div p") // Selects all <p> elements that are descendants of
a <div>
These selectors make it easy to access and manipulate the
DOM, enhancing the interactivity and functionality of web
pages.

You might also like