Random Questions - 1


JSONP Intro

JSONP stands for JSON with Padding.
Requesting a file from another domain can cause problems, due to cross-domain policy.
Requesting an external script from another domain does not have this problem.
JSONP uses this advantage, and request files using the script tag instead of the XMLHttpRequest object.
<script src="demo_jsonp.php">

Access-Control-Allow-Origin is a CORS (Cross-Origin Resource Sharing) header.
When Site A tries to fetch content from Site B, Site B can send an Access-Control-Allow-Origin response header to tell the browser that the content of this page is accessible to certain origins. (An origin is a domain, plus a scheme and port number.) By default, Site B's pages are not accessible to any other origin; using the Access-Control-Allow-Origin header opens a door for cross-origin access by specific requesting origins.
For each resource/page that Site B wants to make accessible to Site A, Site B should serve its pages with the response header:
Access-Control-Allow-Origin: http://siteA.com


Difference between explode() and split() functions with example

The split() function splits the string into an array using a regular expression and returns an array. PHP split function takes three arguments, first one takes pattern regular expression which is case sensitive, second is input string and thirst one is for limit:
split(":", "this:is:a:string"); //returns an array that contains this, is, a, string.

The php explode() function splits the string using delimiter and returns an array.
explode ("this", "we this is a string"); //returns an array that contains array "we", "is a string"

Difference between AJAX and REST web service.

In Ajax, the requests are sent to the server by using XMLHttpRequest objects;
REST have a URL structure and a request/response pattern the revolve around the use of resources.

Ajax eliminates the interaction between the customer and server asynchronously; REST requires the interaction between the customer and server.

Ajax is a set of technology; REST is a type of software architecture and a method for users to request data or information from servers.


JSON.stringify()

A common use of JSON is to exchange data to/from a web server.
When sending data to a web server, the data has to be a string.
Convert a JavaScript object into a string with JSON.stringify().


orders Tbale: orderId, empID, OrderDate, submissionId
employee Table: empID, fname, lname, email, photo

1      Employee name having order more than 5

SELECT e.empID, e.fname, COUNT(o.orderID) as numOrder FROM employee e LEFT JOIN orders o ON e.empID = o.empID GROUP BY o.empID HAVING numOrder >  5;

     Employee name where photo and submissionId missing

SELECT e.id, e.name FROM employee e, orders o WHERE e.id = o.empID AND e.photo = '' GROUP BY e.name;

Order List between Nov and Dec

SELECT o.orderID, e.id, e.name, o.orderDate FROM employee e, orders o WHERE MONTH(  `orderDate` ) = 11 AND e.id = o.empID

select e.name,o.orderDate from employee e, orders o
where e.id = o.empID AND (o.orderDate between '2017-11-11 00:00:00' and '2018-02-11 23:59:00' )

No comments: