Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

W3.JS W3Data


What is W3Data?

W3Data is a tool for bringing server data to HTML applications.

The purpose of W3Data is to provide w3.js with data from a web server.


Application Models

W3Data uses application models (written in JSON) to describe server applications.

This simple model describes a full application for retrieving data from a database:

model_customers.js

{
"database" : {
    "connection" : "localmysql",
    "sql" : "SELECT * FROM Customers"}
}

The models are stored on the server and cannot be edited by a web user.

You have to be a server administrator or a user given the rights to edit files on the server.

Using an application model is easy, just add the model name to w3data.php when you call w3Http():

Example

<script>
w3.getHttpObject("w3data.php?model=model_customers", myFunction);

function myFunction(myObject) {
  w3.displayObject("id01", myObject);
}
</script>
Try It Yourself »

Displaying From a Text File

Example

<script>
w3.getHttpObject("w3data.php?model=model_cd_from_txt", myFunction);

function myFunction(myObject) {
  w3.displayObject("id01", myObject);
}
</script>
Try It Yourself »

This is the model used in the application:

model_cd_from_txt

{
  "data" : {
    "type" : "csvfile",
    "filename" : "cd_catalog.txt",
    "items" : [
      {"name" : "title", "index" : 1},
      {"name" : "artist", "index" : 2},
      {"name" : "price", "index" : 5}
    ]
  }
}

This is the comma separated text file:

cd_catalog.txt

Empire Burlesque,Bob Dylan,USA,Columbia,10.90,1985
Hide your heart,Bonnie Tyler,UK,CBS Records,9.90,1988
Greatest Hits,Dolly Parton,USA,RCA,9.90,1982
Still got the blues,Gary Moore,UK,Virgin records,10.20,1990
Eros,Eros Ramazzotti,EU,BMG,9.90,1997
One night only,Bee Gees,UK,Polydor,10.90,1998
Sylvias Mother,Dr.Hook,UK,CBS,8.10,1973
Maggie May,Rod Stewart,UK,Pickwick,8.50,1990

Displaying From a JSON File

Example

<script>
w3.getHttpObject("w3data.php?model=model_cd_from_json", myFunction);

function myFunction(myObject) {
  w3.displayObject("id01", myObject);
}
</script>
Try It Yourself »

This is the model used in the application:

model_cd_from_json.js

{
  "data" : {
    "type" : "jsonfile",
    "filename" : "cd_catalog.js",
    "record" : "cd"
    "items" : [
      {"name" : "title", "nodename" : "title"},
      {"name" : "artist", "nodename" : "artist"},
      {"name" : "price", "nodename" : "price"}
    ]
  }
}

This is the JSON file:

cd_catalog.js

{
  "cd" : [
    { "title" : "Empire Burlesque", "artist" : "Bob Dylan", "price" : "10.90" },
    { "title" : "Hide your heart", "artist" : "Bonnie Tyler", "price" : "9.90" },
    { "title" : "Greatest Hits", "artist" : "Dolly Parton", "price" : "9.90" },
    { "title" : "Still got the blues", "artist" : "Gary Moore", "price" : "10.20" },
    { "title" : "Eros", "artist" : "Eros Ramazzotti", "price" : "9.90" },
    { "title" : "One night only", "artist" : "Bee Gees", "price" : "10.90" },
    { "title" : "Sylvias Mother", "artist" : "Dr.Hook", "price" : "8.10" }
  ]
}

Displaying From an XML File

Example

<script>
w3.getHttpObject("w3data.php?model=model_cd_from_xml", myFunction);

function myFunction(myObject) {
  w3.displayObject("id01", myObject);
}
</script>
Try It Yourself »

This is the model used in the application:

model_cd_from_xml

{
  "data" : {
    "type" : "xmlfile",
    "filename" : "cd_catalog.xml",
    "record" : "CD",
    "items" : [
      {"name" : "artist", "nodename" : "ARTIST"},
      {"name" : "title", "nodename" : "TITLE"},
      {"name" : "country", "nodename" : "COUNTRY"}
    ]
  }
}

This is the XML file:

cd_catalog.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>Columbia</COMPANY>
<PRICE>10.90</PRICE>
<PUBLISHED>1985</PUBLISHED>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS Records</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1988</PUBLISHED>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<COUNTRY>USA</COUNTRY>
<COMPANY>RCA</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1982</PUBLISHED>
</CD>
<CD>
<TITLE>Still got the blues</TITLE>
<ARTIST>Gary Moore</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Virgin records</COMPANY>
<PRICE>10.20</PRICE>
<PUBLISHED>1990</PUBLISHED>
</CD>
<CD>
<TITLE>Eros</TITLE>
<ARTIST>Eros Ramazzotti</ARTIST>
<COUNTRY>EU</COUNTRY>
<COMPANY>BMG</COMPANY>
<PRICE>9.90</PRICE>
<PUBLISHED>1997</PUBLISHED>
</CD>
<CD>
<TITLE>One night only</TITLE>
<ARTIST>Bee Gees</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>Polydor</COMPANY>
<PRICE>10.90</PRICE>
<PUBLISHED>1998</PUBLISHED>
</CD>
<CD>
<TITLE>Sylvias Mother</TITLE>
<ARTIST>Dr.Hook</ARTIST>
<COUNTRY>UK</COUNTRY>
<COMPANY>CBS</COMPANY>
<PRICE>8.10</PRICE>
<PUBLISHED>1973</PUBLISHED>
</CD>
</CATALOG>

Downloads

Download the file: https://w3.p2hp.com/w3js/w3data.php.txt.

Copy the file to your web site and rename it to w3data.php.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.