0% found this document useful (0 votes)
9 views21 pages

Web Tech ALL

The document contains a series of questions and answers related to web development topics, including PHP, JavaScript, AJAX, XML, and CodeIgniter. It covers various concepts such as response headers, AJAX applications, XML namespaces, JavaScript data types, and the MVC architecture. Additionally, it includes code snippets and examples for practical understanding of these topics.

Uploaded by

anishmaurya2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views21 pages

Web Tech ALL

The document contains a series of questions and answers related to web development topics, including PHP, JavaScript, AJAX, XML, and CodeIgniter. It covers various concepts such as response headers, AJAX applications, XML namespaces, JavaScript data types, and the MVC architecture. Additionally, it includes code snippets and examples for practical understanding of these topics.

Uploaded by

anishmaurya2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Q1.

ONE MARKS QUESTIONS

a) How to set response header in PHP?​


header("Content-Type: text/html");

b) Write any two applications of using AJAX.

1.​ Form validation without page refresh.


2.​ Dynamic content loading like live search suggestions.

c) What are XML namespaces?​


XML namespaces are used to avoid name conflicts by distinguishing elements or attributes
within an XML document.

d) Write the elements of global array $_SERVER.

1.​ $_SERVER['PHP_SELF']
2.​ $_SERVER['SERVER_NAME']
3.​ $_SERVER['HTTP_HOST']
4.​ $_SERVER['REQUEST_METHOD']

e) Give any two limitations of JavaScript.

1.​ Security risks – can be exploited by attackers.


2.​ Browser dependency – may work differently in different browsers.

f) Whether root element is required for XML file? If so, how many root elements are
required?​
Yes, one root element is required.

g) What is the use of isNaN() function in JavaScript?​


It checks whether a value is NaN (Not-a-Number).

h) What are different values of readyState property of XMLHttpRequest?


1.​ 0 – UNSENT
2.​ 1 – OPENED
3.​ 2 – HEADERS_RECEIVED
4.​ 3 – LOADING
5.​ 4 – DONE

i) List out parts of XML document structure.

1.​ XML Declaration


2.​ Root Element
3.​ Child Elements
4.​ Attributes
5.​ Comments

j) Which function is used to create cookie in PHP? Give syntax of it.​


Function: setcookie()​
Syntax:​
setcookie(name, value, expire, path, domain, secure);

k) Enlist the characteristics of XML.

1.​ Self-descriptive tags.


2.​ Supports nested elements.
3.​ Platform-independent.
4.​ Extensible.

l) What do you mean by sticky form?​


A sticky form retains previously entered values after submission.

m) Which information is stored in $_FILES?

1.​ File Name


2.​ File Type
3.​ File Size
4.​ Temporary File Name
5.​ Error Code
n) Justify True or False - XML Parser cannot alter documents or create new
documents.​
True – XML Parsers only read and parse documents, they do not modify or create them.

o) What is DOM?​
The Document Object Model (DOM) is a programming interface that allows scripts to update
content, structure, and style of documents.

p) Give any two applications of AJAX.

1.​ Auto-saving form data in background.


2.​ Live chat applications.

q) What is jQuery?​
jQuery is a fast, lightweight JavaScript library for DOM manipulation, animations, event
handling, and AJAX interactions.

r) What is CodeIgniter?​
CodeIgniter is a lightweight PHP framework based on the MVC architecture.

s) What is the use of XMLHttpRequest object?​


It allows JavaScript to send HTTP requests to the server without page reload.

t) What is the use of redirect() function in CodeIgniter?​


It redirects the user to another URL or controller method.

u) Which function is used to print an error message and exit from current code?​
die() or exit()

v) What is sticky form?​


A form that retains user input values after submission.
w) XML Parser cannot alter documents or create new documents. Justify True or
False.​
→ True – XML Parsers can only parse and read XML documents.

x) What is DOM?​
The Document Object Model (DOM) is an interface that represents HTML or XML
documents as a tree structure, enabling manipulation via scripting languages.

y) How the variables declared in JavaScript?​


Using: var, let, or const

z) What is jQuery?​
jQuery is a fast, lightweight JavaScript library for simplifying HTML DOM manipulation,
animations, and AJAX calls.

a) Give any two applications of AJAX.

1.​ Dynamic content loading without refreshing the page.


2.​ Auto-complete search suggestions.

ab) Which object makes web pages interactive using AJAX?​


XMLHttpRequest

c) What is CodeIgniter?​
CodeIgniter is a PHP framework that follows the MVC architecture for rapid web application
development.

a) Which function is used for page redirecting?​


header("Location: URL");






Q2. TWO MARKS QUESTIONS

a) List any four datatypes that JavaScript supports with its usage.

Datatype Usage Example

Number var age = 25;

String var name = "John";

Boolean var isActive = true;

Object var person = {name: "John", age:


25};

b) How to start and destroy session in PHP? Give syntax.

●​ Start Session:​
session_start();
●​ Destroy Session:​
session_destroy();

c) Draw AJAX web application model.

Diagram Required – Please draw it manually.​


Refer Page 4.2 in textbook.​
It contains:

●​ User interface
●​ AJAX Engine (XMLHttpRequest)
●​ Server-side components (Database/Business Logic)

d) What is MVC?

●​ MVC stands for Model-View-Controller.


●​ It separates application logic into 3 parts:
○​ Model – Handles data and business logic.
○​ View – Displays data (UI).
○​ Controller – Manages user input and links Model & View.
e) What are different rules to make XML document well-formed?

1.​ Must have a single root element.


2.​ All tags must be properly nested.
3.​ All tags must be closed.
4.​ Attribute values must be quoted.
5.​ Tags are case-sensitive.

f) What is session? How to start the new session?

●​ Session: A way to store user-specific data across multiple pages.


●​ Start Session: session_start();

g) Explain the structure of well-formed XML document.

A well-formed XML document contains:

1.​ XML Declaration: <?xml version="1.0"?>


2.​ Root Element: Contains all other elements.
3.​ Child Elements: Nested within root element.
4.​ Attributes: Key-value pairs within elements.
5.​ Proper Tag Nesting and Closure.

h) Explain pop-up boxes in JavaScript.

1.​ Alert Box: alert("This is an alert box.");


○​ Displays a simple message with OK button.
2.​ Confirm Box: confirm("Are you sure?");
○​ Displays a message with OK and Cancel buttons.
3.​ Prompt Box: prompt("Enter your name:");
○​ Asks for user input with text box.

i) Discuss similarities and differences between GET and POST method.

Similarities Differences

Both are used to send form data to GET appends data to URL, POST sends data in
server. request body.

Both use HTTP protocol. GET has size limit (about 2000 characters), POST
has no limit.
Both can use $_REQUEST to GET is less secure (visible in URL), POST is more
access data. secure.

Both can send text data. POST supports binary data (files upload), GET does
not.

j) Explain asynchronous mode in Ajax.

●​ In asynchronous mode, the browser does not wait for a response from the server.
●​ The user can continue interacting with the page while the request is processed in the
background.
●​ Example: Fetching suggestions in a search bar.

k) Discuss differences between GET and POST method.

GET POST

Data sent in URL. Data sent in HTTP body.

Less secure. More secure.

Limited data (about 2000 No size limit.


chars).

Can be bookmarked. Cannot be bookmarked.

Visible data in URL. Data hidden from URL.

l) Explain any five elements of $_SERVER variable.

Element Description

$_SERVER['PHP_SELF'] Current script filename.

$_SERVER['SERVER_NAME'] Name of host server.

$_SERVER['REQUEST_METHOD'] HTTP request method


(GET/POST).

$_SERVER['HTTP_HOST'] Host header from request.

$_SERVER['REMOTE_ADDR'] IP address of the client.


n) Draw and explain AJAX web application module.

Diagram Required – Please draw manually.​


Explanation:

●​ User Interface: HTML interface seen by user.


●​ AJAX Engine: Handles communication using XMLHttpRequest.
●​ Server Side Components: Receives requests, processes data, returns responses.
●​ Database/Business Logic: Data processing/storage.

































Q3. FOUR MARKS QUESTIONS

a) Explain the JavaScript confirm dialog box with a suitable example.

●​ The confirm() method displays a dialog box with a message, an OK button, and a
Cancel button.
●​ It returns true if OK is clicked and false if Cancel is clicked.
●​ It is used to confirm user actions, such as deleting records.​

Example:

var result = confirm("Are you sure you want to delete this record?");

if(result) {

alert("Record Deleted");

} else {

alert("Action Cancelled");

b) Explain CodeIgniter architecture with a suitable diagram.

Explanation:

●​ Model: Handles data logic and database interactions.


●​ View: Displays data (HTML, CSS, etc.).
●​ Controller: Controls request flow between Model and View.
●​ Helpers/Libraries: Pre-built functions for common tasks.
●​ Config Files: Configuration settings for database, routes, etc.

c) What are different techniques to maintain state in PHP?

Technique Description

Hidden Fields Data passed through hidden form inputs.

URL Rewriting Data passed as query string in URL.

Cookies Small data stored in user's browser and sent with each request.
Sessions Data stored on server, identified via session ID sent as cookie or in
URL.

a) Write an AJAX program to display list of countries stored in an array on clicking OK


button.​
→​
<!DOCTYPE html>

<html>

<head>

<script>

function showCountries() {

var xhr = new XMLHttpRequest();

xhr.open("GET", "countries.php", true);

xhr.onreadystatechange = function() {

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

document.getElementById("result").innerHTML = xhr.responseText;

xhr.send();

</script>

</head>

<body>

<button onclick="showCountries()">OK</button>

<div id="result"></div>

</body>

</html>
→​
<?php

$countries = ["India", "USA", "UK", "Germany", "France"];

echo implode(", ", $countries);

?>

b) Design HTML form to accept Employee name, Age, Mobile no. & perform
validations using JavaScript.​
→​
<!DOCTYPE html>

<html>

<body>

<form onsubmit="return validateForm()">

Employee Name: <input type="text" id="name"><br>

Age: <input type="text" id="age"><br>

Mobile No: <input type="text" id="mobile"><br>

<input type="submit" value="Submit">

</form>

<script>

function validateForm() {

var name = document.getElementById("name").value;

var age = document.getElementById("age").value;

var mobile = document.getElementById("mobile").value;

if(name == "" || age == "" || mobile == "") {

alert("All fields are required.");

return false;
}

if(mobile.length != 10 || isNaN(mobile)) {

alert("Mobile number must be 10 digits.");

return false;

return true;

</script>

</body>

</html>

c) Modify books.xml category attribute to "food" using XML DOM.​


var x = xmlDoc.getElementsByTagName("book")[0];

x.setAttribute("category", "food");

a) What is XML parser? Explain types.​


XML Parser: A tool to read, process, and convert XML into readable data for applications.

Types:

Parser Description

DOM Parser Loads entire XML into memory as tree structure (read/write).

SAX Parser Reads XML sequentially without loading into memory (read-only).

SimpleXML Converts XML to PHP objects (easy to use).


XMLReader Forward-only, read-only parser.

b) Explain workflow of MVC architecture.

Step Description

1 User requests page (via URL).

2 Controller receives request, calls


Model.

3 Model fetches data (from DB).

4 Controller passes data to View.

5 View renders page with data.​

c) Write note on AJAX Web Application Model.

●​ AJAX model consists of:

Component Description

User Interface HTML page displayed in browser.

AJAX Engine JavaScript + XMLHttpRequest handling background


requests.
Server-side PHP/Servlets handling requests, DB queries, and responses.
Script

Database Stores data fetched or updated via AJAX.

a) JavaScript code to validate employee’s name & age.​


var name = prompt("Enter Employee Name:");

var age = prompt("Enter Age:");

if(name == null || name == "") {

alert("Name is required.");

} else if(age < 18) {

alert("Age must be greater than 18.");

} else {

alert("Welcome " + name + ", Age: " + age);

}​

b) AJAX program for Doctor table (dno, dname, experience).

<select id="doctor" onchange="getDoctorDetails()">

<option value="1">Dr. Smith</option>

<option value="2">Dr. John</option>

</select>
<div id="details"></div>

<script>

function getDoctorDetails() {

var dno = document.getElementById("doctor").value;

var xhr = new XMLHttpRequest();

xhr.open("GET", "doctorDetails.php?dno=" + dno, true);

xhr.onreadystatechange = function() {

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

document.getElementById("details").innerHTML = xhr.responseText;

xhr.send();

</script>​
doctorDetails.php:

$doctors = [

1 => ["dname" => "Dr. Smith", "experience" => "10 years"],

2 => ["dname" => "Dr. John", "experience" => "15 years"]

];

$dno = $_GET['dno'];

if(isset($doctors[$dno])) {

echo "Doctor Name: " . $doctors[$dno]["dname"] . "<br>";

echo "Experience: " . $doctors[$dno]["experience"];

}
c) PHP script for session-based page access count.

<?php

session_start();

if(!isset($_SESSION['count'])) {

$_SESSION['count'] = 1;

} else {

$_SESSION['count']++;

echo "This page has been accessed " . $_SESSION['count'] . "


times.";

?>

a) Workflow of MVC Architecture. (Repeated – Refer above)

b) Fields used in Cookies.

Field Description

Name Cookie identifier.

Value Cookie data.

Expiry Expiration date/time.


Path URL path where cookie is
accessible.

Domain Domain where cookie works.

Secure Whether cookie is HTTPS only.

a) JavaScript alert, prompt, confirm example.

alert("Exams are near, Prepare well for it!");

var name = prompt("Enter your name:");

if(name) {

var confirmStudy = confirm("Are you ready for the exams, " +


name + "?");

if(confirmStudy) {

alert("All the best!");

} else {

alert("Start preparing soon!");

} else {

alert("Name is required!");

}
b) PHP + jQuery to append paragraph and ordered list items.

<!DOCTYPE html>

<html>

<head>

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

<script>

$(document).ready(function() {

$("#addPara").click(function() {

$("p").append(" Added Text.");

});

$("#addList").click(function() {

$("ol").append("<li>New Item</li>");

});

});

</script>

</head>

<body>

<p>Paragraph Text</p>

<ol><li>Item 1</li></ol>

<button id="addPara">Add Paragraph Text</button>

<button id="addList">Add List Item</button>

</body>

</html>
Q4. THREE MARKS QUESTIONS

a) What is XML parser? Explain two different types of XML parsers.

→​
XML Parser: An XML parser is a tool that reads, processes, and extracts data from XML
documents.

Types:

Type Description

DOM Loads entire XML document into memory as a tree structure, allows read &
Parser write operations. Suitable for small XML files.

SAX Processes XML data sequentially, does not load the entire document into
Parser memory. Suitable for large XML files, read-only.

b) Write down the steps to integrate external CSS and JS file in


CodeIgniter. Give example.

→​
Steps:

1.​ Store Files - Place CSS in assets/css/ and JS in assets/js/.


2.​ Load Files in View - Use <link> and <script> tags in View file.

Example:

<link rel="stylesheet" type="text/css" href="<?php echo


base_url('assets/css/style.css'); ?>">

<script src="<?php echo base_url('assets/js/script.js');


?>"></script>

3.​ Configure base URL in config/config.php:


$config['base_url'] = 'http://localhost/yourproject/';

a) Write XML syntax rules.

1.​ Every XML document must have one root element.


2.​ All tags must be properly nested.
3.​ All tags must be properly closed.
4.​ Attribute values must be enclosed in quotes.
5.​ Tags and attributes are case-sensitive.
6.​ Special characters must be escaped (<, >, &, etc.).

b) What are jQuery selectors? Explain in brief.

jQuery selectors are used to select and manipulate HTML elements using CSS-like
syntax.

Types:

Selector Description Example

#id Selects element by ID $("#header")

.class Selects elements by class $(".btn")

element Selects all elements $("p")

attribute Selects elements with $("[type='text']


attribute ")

:first Selects the first element $("li:first")


You might also like