Module 4,5 and 6 Imp Ques
Module 4,5 and 6 Imp Ques
Module 4,5 and 6 Imp Ques
Question Bank
3. How is AJAX architecture different from the traditional Web application model
Ans:
Conventional model AJAX model
The browser sends an HTTP request to the The browser creates a JavaScript call, which
server. then creates a new XMLHttpRequest object.
The new XMLHttpRequest object transfers
The web server receives and processes the
data between the browser and the web server
request.
in an XML format.
The XMLHttpRequest object sends a request
The web server sends the requested data to for the updated page data to the web server.
the browser. Subsequently, the latter processes the request
and sends it back to the browser.
The browser receives the data from the server The browser uses JavaScript to process the
and reloads it as an HTML page. response and displays the updated content
6. State the various ways of receiving response from server using AJAX. Support your
answer with an example [05]
Ans: Various ways of receiving response from a server, is by using responseText or
responseXML property of the XMLHttpRequest object.
a) The responseText Property: If the response from the server is not XML,
use the responseText property. The responseText property returns the
response as a string, and you can use it accordingly
b) The responseXML Property: If the response from the server is XML, and
you want to parse it as an XML object, use the responseXML property.
Example:
<!DOCTYPE html>
<html> <body>
<div id="demo">
<h2>The XMLHttpRequest Object</h2>
<button type="button" onclick="loadDoc()">Change Content</button>
</div>
<script>
function loadDoc() {
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
document.getElementById("demo").innerHTML = this.responseText;
}
xhttp.open("GET", "Hello.txt");
xhttp.send();
}
</script> </body> </html>
7. How jQuery uses GET and POST methos to request data from server [05]
Ans:
jQuery $.get() Method: The $.get() method requests data from the server with an
HTTP GET request.
Syntax: $.get(URL,callback);
The required URL parameter specifies the URL you wish to request.
The optional callback parameter is the name of a function to be executed if the
request succeeds.
The following example uses the $.get() method to retrieve data from a file on
the server:
jQuery $.post() Method: The $.post() method requests data from the server using an
HTTP POST request.
Syntax: $.post(URL,data,callback);
The required URL parameter specifies the URL you wish to request.
The optional data parameter specifies some data to send along with the request.
The optional callback parameter is the name of a function to be executed if the
request succeeds.
The following example uses the $.post() method to send some data along with
the request:
$("button").click(function(){
$.post("demo_post.asp",
{
name: "Ankita",
city: "Kandivali"
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
Unit 5: Web Extensions: PHP and XML
1. Distinguish between echo and print statement in PHP [02]
Ans:
echo statement print statement
2. Associative Array: Associative arrays are arrays that use named keys that
you assign to them.
Example:
<?php
$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");
foreach($age as $x => $x_value) {
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
} ?>
3. Multidimensional Array: A multidimensional array is an array containing
one or more arrays. PHP supports multidimensional arrays that are two,
three, four, five, or more levels deep.
<?php
$emp = array
(
array(1,"sonu",400000),
array(2,"john",500000),
array(3,"rahul",300000)
);
for ($row = 0; $row < 3; $row++) {
for ($col = 0; $col < 3; $col++) {
echo $emp[$row][$col]." ";
}
echo "<br/>";
} ?>
4. Create an HTML form that accepts Emp_Id, First_Name, Last_Name and Gender from
user. Write a PHP code to store this information into Employee table using MySQL
database [05]
connect.php
<?php
session_start();
$dbHost='localhost';
$dbName='Employee';
$dbUsername='root';
$dbPassword='';
$dbc=mysqli_connect($dbHost,$dbUsername,$dbPassword,$dbName);
if(!$dbc){
die('Could not Connect My Sql:' .mysql_error());
}
// else{
// echo "Connected";
// }
?>
Data.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-
scale=1.0">
<title>Details</title>
</head>
<body>
<form action="insert.php" method="post">
Employee Id : <input type="text" name="eid">
<br><br>
First Name : <input type="text" name="fname">
<br><br>
Last Name : <input type="text" name="lname">
<br><br>
Gender : <input type="text" name="gender">
<input type="submit" value="Submit" name="save">
</form>
</body>
</html>
insert.php
<?php
include"connect.php";
if(isset($_POST['save']))
{
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$emp_id = $_POST['eid'];
$Gender = $_POST['gender'];
$sql = "INSERT INTO Emp_Details
(Emp_Id,First_Name,Last_Name,Gender)
VALUES ('$emp_id','$first_name','$last_name','$Gender')";
if (mysqli_query($dbc,$sql)) {
echo "New record created successfully !";
} else {
echo "Error: " . $sql . " " . mysqli_error($dbc);
}
mysqli_close($dbc);
}
?>
5. Display the following information using XML and XSLT [05]
<store>
<book id ="5350192956">
<bookname>XSLT Programmer's Reference</bookname>
<authorname>Michael Kay</authorname>
<publisher>Wrox</publisher>
<price>$40</price>
<edition>4th</edition>
</book>
<book id ="3741122298">
<bookname>Head First Java</bookname>
<authorname>Kathy Sierra</authorname>
<publisher>O'reilly</publisher>
<price>$19</price>
<edition>1st</edition>
</book>
<book id ="9987436700">
<bookname>SQL The Complete Reference</bookname>
<authorname>James R. Groff</authorname>
<publisher>McGraw-Hill</publisher>
<price>$45</price>
<edition>3rd</edition>
</book>
</store>
QBank.xsl
Synatx:
foreach ($array as $value) {
//code to be executed
}
Example:
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
Unit 6: ReactJS
1. State features of ReactJS [02]
2. Create a simple application using ReactJS [02