X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Web Building - Data as a Service (DaaS)


Building a web site from scratch.   Part VIII: Data as a service.


What We Will Do

In this chapter we will:

  • Fetch dynamic data from a web server with SQL

Using a PHP Server Running MySQL

In the DemoWeb folder, change the file Customers.html.

Put the following code inside the file:

Customers.html

<!DOCTYPE html>
<html>

<head>
  <title>Our Company</title>
  <link href="Site.css" rel="stylesheet">
</head>

<body>

<nav id="nav01"></nav>

<div id="main">
  <h1>Customers</h1>
  <div id="id01"></div>
  <footer id="foot01"></footer>
</div>

<script src="Script.js"></script>

<script>
var xmlhttp = new XMLHttpRequest();
var url = "http://www.w3schools.com/website/Customers_MYSQL.php";

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("id01").innerHTML =
        xmlhttp.responseText;
    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
</script>

</body>
</html>

Try it Yourself »

The code above is the same as in the previous chapter.

This time the XMLHttpRequest reads data from "Customers_MYSQL.php".

Customers_MYSQL.php fetches data from a "live" database, while Customers_JSON.php fetches a "static" text file.


Using an ASP.NET Server Running SQL Server

In the DemoWeb folder, change the file Customers.html.

Put the following code inside the file:

Customers.html

<!DOCTYPE html>
<html>

<head>
  <title>Our Company</title>
  <link href="Site.css" rel="stylesheet">
</head>

<body>

<nav id="nav01"></nav>

<div id="main">
  <h1>Customers</h1>
  <div id="id01"></div>
  <footer id="foot01"></footer>
</div>

<script src="Script.js"></script>

<script>
var xmlhttp = new XMLHttpRequest();
var url = "http://www.w3schools.com/website/Customers_SQL.aspx";

xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        document.getElementById("id01").innerHTML =
        xmlhttp.responseText;
    }
}
xmlhttp.open("GET", url, true);
xmlhttp.send();
</script>

</body>
</html>

Try it Yourself »


Read More

Read more about SQL in our SQL Tutorial.



Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook