SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
AJAX
                           CRIA Webtechnology
Thursday, March 18, 2010
Some applications of AJAX
 2

          Validation
          Dynamic listboxes
          Autorefresh
          Excessive tooltips
          Calling webservices




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
AJAX
 3

          Asynchronous Javascript And XML

          No DOM Standard, equals implementation in several
           browsers through the XMLHttpRequest




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver

                                                                      Server
                                                                      Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Databaseserver



          event                                                       DB




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver

                                                                      Server
                                                                      Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Databaseserver


                            1                                         DB
          event




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver
                                                   3
                                                                      Server
                                                                      Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Databaseserver


                            1                                         DB
          event




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver
                                                   3
                                                                      Server
                                                                      Resource
          XHR
                           function callback()
                           {                                                     4
           2               }
                                                        Databaseserver


                            1                                         DB
          event




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver
                                                   3
                                                                      Server
                                                                      Resource
          XHR
                                                   5
                           function callback()
                           {                                                     4
           2               }
                                                        Databaseserver


                            1                                         DB
          event




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 4



       AJAX Enabled Web App.                            Webserver
                                                   3
                                                                      Server
                                                                      Resource
          XHR
                                                   5
                           function callback()
                           {                                                     4
           2               }            6
                                                        Databaseserver


                            1                                         DB
          event




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 5
           HTML:
       <div id="emailSection">
               <input id="email" type="text"
                 onblur="new
                  ValidationServiceRequestor().validateEmail();"/>
               <label>Emailadres</label>
       </div>

       JAVASCRIPT:
       var ValidationServiceRequestor = function(){
       	    this.validateEmail = function(){
       	    	    var emailaddress = document.getElementById("email");
       	    	    var serviceProxy = new ValidationServiceProxy(this);
       	    	    serviceProxy.validateEmail(emailaddress);
       	    }
       	    this.setValid = function(isValid){
       	    	    alert(isValid)
       	    }
       }

                                CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 6
             var ValidationServiceProxy = function(callbackObject){
           this.validateEmail = function(emailaddress){
               validateEmailRequest = getXmlHttpRequestObject();
               if (validateEmailRequest.readyState == 4 || validateEmailRequest.readyState == 0) {
       	             var params = "method=validateEmail&emailaddress=" + emailaddress.value;
                   validateEmailRequest.open("GET", 'validationService.php?' + params, true);
                   validateEmailRequest.onreadystatechange = validateEmailResponse;
                   validateEmailRequest.send(null);
               }
           }
           validateEmailResponse = function(){
               if (validateEmailRequest.readyState == 4) {
                  var isEmailValid = eval("(" + validateEmailRequest.responseText + ")");
                  var isValid = (isEmailValid[0].emailaddressCount == 0)
                  callbackObject.setValid(isValid)
               }
           }
           getXmlHttpRequestObject = function(){
               if (window.XMLHttpRequest) {
                   return new XMLHttpRequest();
               }
               else {
                   if (window.ActiveXObject) {
                       return new ActiveXObject("Microsoft.XMLHTTP");
                   }
               }
           }
       }
                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest - Callback
 7

        function callback() {
          if (xmlHttp.readyState == 4) {
             if (xmlHttp.status == 200) {
             //do something interesting here
             }
          }
        }



                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest
 8

          You aren't allowed to make XMLHttpRequests to any
           server except the server where your web page
           came from.




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy

                                                                       Server
                                                                       Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Webserver
                                                        in other domain


          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy

                                                                       Server
                                                                       Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Webserver
                                                        in other domain

                            1
          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy
                                                   3
                                                                       Server
                                                                       Resource
          XHR
                           function callback()
                           {
           2               }
                                                        Webserver
                                                        in other domain

                            1
          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy
                                                   3
                                                                       Server
                                                                       Resource
          XHR
                           function callback()
                           {                                                      4
           2               }
                                                        Webserver
                                                        in other domain

                            1
          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy
                                                   3
                                                                       Server
                                                                       Resource
          XHR
                                                   5
                           function callback()
                           {                                                      4
           2               }
                                                        Webserver
                                                        in other domain

                            1
          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XMLHttpRequest: Application Proxy
 9



       AJAX Enabled Web App.                            Webserver: Application Proxy
                                                   3
                                                                       Server
                                                                       Resource
          XHR
                                                   5
                           function callback()
                           {                                                      4
           2               }            6
                                                        Webserver
                                                        in other domain

                            1
          event                                                       WebService




                                          CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                          Webserver in other domain
                                                        Server
                                                        Resource
          <script>
          </script>
                                                        returns js


          2




          event                                        WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                              Webserver in other domain
                                                            Server
                                                            Resource
          <script>
          </script>
                                                            returns js


          2



                           1
          event                                            WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                              Webserver in other domain
                                        3                   Server
                                                            Resource
          <script>
          </script>
                                                            returns js


          2



                           1
          event                                            WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                              Webserver in other domain
                                        3                   Server
                                                            Resource
          <script>
          </script>
                                                            returns js


          2                                                              4




                           1
          event                                            WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                              Webserver in other domain
                                        3                   Server
                                                            Resource
          <script>
          </script>
                                                            returns js
                                        5

          2                                                              4




                           1
          event                                            WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
On Demand JavaScript
10



       Web App.                                  Webserver in other domain
                                 <script id="external_script"
                                              3
                                 type="text/JavaScript"> Server
                               </script>                      Resource
          <script>
          </script>            <script>                       returns js
                                              5
                                 document.getElementById('external_script').src
                                   = 'http://cross.domain.com/other.js'; 4
          2                    </script>



                           1
          event                                                   WebService


       http://ajaxpatterns.org/On-Demand_Javascript
                                      CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
XML AND JSON
Thursday, March 18, 2010
XML vs JSON
12


       XML                                 JSON

       <employee>                          var employee = {
       <firstName>John</firstName>             "firstName" : John
       <lastName>Doe</lastName>                , "lastName" : Doe
       <empNr>123</empNr>                      , "empNr" : 123
       <title>Accountant</title>               , "title" : "Accountant"
       </employee>                         }




                             CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
JSON Is Not...
13

          JSON is not a document format.
          JSON is not a markup language.
          JSON is not a general serialization format.
             No recursive/recurring structures.
             No invisible structures.
             No functions.




                              CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Object
14
        {
                "name":              "Jack B. Nimble",
                "at large": true,
                "grade":             "A",
                "format": {
                           "type":          "rect",
                           "width":         1920,
                           "height":        1080,
                           "interlace": false,
                           "framerate": 24
                }
        }                              CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
JSON in Ajax
15

          XMLHttpRequest
             Obtain  responseText
             Parse the responseText


                 responseData     = eval(
                      '(' + responseText + ')');

                 responseData    =
                      responseText.parseJSON();



                                    CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Security
16

          Is it safe to use eval with XMLHttpRequest?
          The JSON data comes from the same server that
           vended the page. An eval of the data is no less
           secure than the original html.
          If in doubt, use string.parseJSON instead of eval.




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
JSON Is Not XML
17

          objects                           element
          arrays                            attribute
          strings                           attribute string
          numbers                           content
          booleans                          <![CDATA[ ]]>
          null                              entities
                                             declarations
                                             schema
                                             stylesheets
                                             comments
                                             version
                                             namespace



                           CRIA WT - Rody Middelkoop

Thursday, March 18, 2010
Server-side JSON
18

            <?php
       	    $emailaddresses = getDataFromDataSource(
       "SELECT COUNT(*) AS emailaddressCount from adresboek where emailaddress = '" .
       $_REQUEST["emailaddress"] ."'");
       	    $emailaddressesForJSON = array();
       	    while( $row = mysql_fetch_array($emailaddresses))
       	    {
       	    	    array_push($emailaddressesForJSON, $row);
       	    }
       	    $jsonText = json_encode( $emailaddressesForJSON );
       	    echo $jsonText;

       function getDataFromDataSource($query)
       {
       	    mysql_connect("127.0.0.1", "root", "root")
              or die("Connection Failure to Database");
       	    mysql_select_db("criademo") or die ("Database criademo not found.");
       	    $result = mysql_query($query);
       	    return $result;
       }
       ?>

                                  CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Who is responsible for the right
19
       format?
       Web App.                          Webserver


                                                       WebService
          Client




          event




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Who is responsible for the right
19
       format?
       Web App.                              Webserver


                                                           WebService
          Client




                           1
          event




                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Who is responsible for the right
19
       format?
       Web App.                              Webserver
                                        2
                                                           WebService
          Client




                           1
          event




                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Who is responsible for the right
19
       format?
       Web App.                              Webserver
                                        2
                                                           WebService
          Client
                                        3




                           1
          event




                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Who is responsible for the right
19
       format?
       Web App.                              Webserver
                                        2
                                                           WebService
          Client
                                        3



                                               1.SOAP: returns XML
                                               2.REST: let the client pick a
                           1                   format like XML, JSON, HTML
          event




                               CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010
Resources and a big thank you
20

          JSON the x in AJAX, www.json.org/json.pdf
       




                           CRIA-WT - Rody Middelkoop

Thursday, March 18, 2010

Contenu connexe

Tendances (8)

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Transforming Mobile Push Notifications with Big Data
Transforming Mobile Push Notifications with Big DataTransforming Mobile Push Notifications with Big Data
Transforming Mobile Push Notifications with Big Data
 
Reusing existing data_layer_to_persist_multi_f
Reusing existing data_layer_to_persist_multi_fReusing existing data_layer_to_persist_multi_f
Reusing existing data_layer_to_persist_multi_f
 
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSCRMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
RMLL 2013 - Synchronize OpenLDAP and Active Directory with LSC
 
最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと最新のデータベース技術の方向性で思うこと
最新のデータベース技術の方向性で思うこと
 
Synchronize OpenLDAP with Active Directory with LSC project
Synchronize OpenLDAP with Active Directory with LSC projectSynchronize OpenLDAP with Active Directory with LSC project
Synchronize OpenLDAP with Active Directory with LSC project
 
Introduction to Mongodb
Introduction to MongodbIntroduction to Mongodb
Introduction to Mongodb
 
Mapserver vs Geoserver
Mapserver vs GeoserverMapserver vs Geoserver
Mapserver vs Geoserver
 

En vedette

PHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWSPHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWS
benwaine
 
Turning Marketing Words into a Branded People Experience
Turning Marketing Words into a Branded People ExperienceTurning Marketing Words into a Branded People Experience
Turning Marketing Words into a Branded People Experience
Bridge Training and Events
 
Web Security Introduction Webserver hacking refers to ...
Web Security Introduction Webserver hacking refers to ...Web Security Introduction Webserver hacking refers to ...
Web Security Introduction Webserver hacking refers to ...
webhostingguy
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
guileen
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
Satish b
 

En vedette (17)

Nodejs
NodejsNodejs
Nodejs
 
PHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWSPHPNW14 - Getting Started With AWS
PHPNW14 - Getting Started With AWS
 
Turning Marketing Words into a Branded People Experience
Turning Marketing Words into a Branded People ExperienceTurning Marketing Words into a Branded People Experience
Turning Marketing Words into a Branded People Experience
 
Web Security Introduction Webserver hacking refers to ...
Web Security Introduction Webserver hacking refers to ...Web Security Introduction Webserver hacking refers to ...
Web Security Introduction Webserver hacking refers to ...
 
Basic Website 101
Basic Website 101Basic Website 101
Basic Website 101
 
Summer training seminar
Summer training seminarSummer training seminar
Summer training seminar
 
Web Fendamentals
Web FendamentalsWeb Fendamentals
Web Fendamentals
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 
Joomla REST API
Joomla REST APIJoomla REST API
Joomla REST API
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
 
Server side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHPServer side scripting smack down - Node.js vs PHP
Server side scripting smack down - Node.js vs PHP
 
Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.Webservices: connecting Joomla! with other programs.
Webservices: connecting Joomla! with other programs.
 
SmokeTests
SmokeTestsSmokeTests
SmokeTests
 
WebSphere App Server vs JBoss vs WebLogic vs Tomcat
WebSphere App Server vs JBoss vs WebLogic vs TomcatWebSphere App Server vs JBoss vs WebLogic vs Tomcat
WebSphere App Server vs JBoss vs WebLogic vs Tomcat
 
Client Vs. Server Rendering
Client Vs. Server RenderingClient Vs. Server Rendering
Client Vs. Server Rendering
 
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
WebSphere App Server vs JBoss vs WebLogic vs Tomcat (InterConnect 2016)
 
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
How To Deploy A Cloud Based Webserver in 5 minutes - LAMPHow To Deploy A Cloud Based Webserver in 5 minutes - LAMP
How To Deploy A Cloud Based Webserver in 5 minutes - LAMP
 

Similaire à Ajax And JSON

Similaire à Ajax And JSON (20)

Ajax
AjaxAjax
Ajax
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Ajax
AjaxAjax
Ajax
 
Ajax Lecture Notes
Ajax Lecture NotesAjax Lecture Notes
Ajax Lecture Notes
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
SynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client librarySynapseIndia dotnet development ajax client library
SynapseIndia dotnet development ajax client library
 
Ajax
AjaxAjax
Ajax
 
Suga ajax training
Suga ajax trainingSuga ajax training
Suga ajax training
 
AJAX
AJAXAJAX
AJAX
 
RicoAjaxEngine
RicoAjaxEngineRicoAjaxEngine
RicoAjaxEngine
 
RicoAjaxEngine
RicoAjaxEngineRicoAjaxEngine
RicoAjaxEngine
 
Ajax tutorial by bally chohan
Ajax tutorial by bally chohanAjax tutorial by bally chohan
Ajax tutorial by bally chohan
 
Rails MVC Architecture
Rails MVC ArchitectureRails MVC Architecture
Rails MVC Architecture
 
ASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep DiveASP.NET Core 3.0 Deep Dive
ASP.NET Core 3.0 Deep Dive
 
Java EE and Glassfish
Java EE and GlassfishJava EE and Glassfish
Java EE and Glassfish
 
Ajax
AjaxAjax
Ajax
 
What's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer featuresWhat's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer features
 
Slide 3 Fast Data processing with kafka, rfx and redis
Slide 3 Fast Data processing with kafka, rfx and redisSlide 3 Fast Data processing with kafka, rfx and redis
Slide 3 Fast Data processing with kafka, rfx and redis
 
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
Wakanda: a new end-to-end JavaScript platform - JSConf Berlin 2009
 

Plus de Rody Middelkoop

Plus de Rody Middelkoop (19)

Integration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubsIntegration and Unit Testing in Java using Test Doubles like mocks and stubs
Integration and Unit Testing in Java using Test Doubles like mocks and stubs
 
An agile mindset in education
An agile mindset in education An agile mindset in education
An agile mindset in education
 
Themalunch scrum
Themalunch scrumThemalunch scrum
Themalunch scrum
 
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpakEduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
Eduscrum presentatie Scrum event 2016: Scrum als onderwijsaanpak
 
Pecha Kucha eduScrum Agile Education
Pecha Kucha eduScrum Agile EducationPecha Kucha eduScrum Agile Education
Pecha Kucha eduScrum Agile Education
 
Unit Testing Android Applications
Unit Testing Android ApplicationsUnit Testing Android Applications
Unit Testing Android Applications
 
Software Process Models
Software Process ModelsSoftware Process Models
Software Process Models
 
Softwarekwaliteit in een ontwikkelstraat
Softwarekwaliteit in een ontwikkelstraatSoftwarekwaliteit in een ontwikkelstraat
Softwarekwaliteit in een ontwikkelstraat
 
JavaScript on the server - Node.js
JavaScript on the server - Node.jsJavaScript on the server - Node.js
JavaScript on the server - Node.js
 
DDOA = Software Craftmanship
DDOA = Software CraftmanshipDDOA = Software Craftmanship
DDOA = Software Craftmanship
 
Back to the Future: Onderwijs van 1991 tot 2031
Back to the Future: Onderwijs van 1991 tot 2031Back to the Future: Onderwijs van 1991 tot 2031
Back to the Future: Onderwijs van 1991 tot 2031
 
Scrum implemented in an educational context
Scrum implemented in an educational contextScrum implemented in an educational context
Scrum implemented in an educational context
 
OO JavaScript
OO JavaScriptOO JavaScript
OO JavaScript
 
Pragmatic Model Driven Development In Java Using Smart Use Cases
Pragmatic Model Driven Development In Java Using Smart Use CasesPragmatic Model Driven Development In Java Using Smart Use Cases
Pragmatic Model Driven Development In Java Using Smart Use Cases
 
Scrum in informaticaonderwijs
Scrum in informaticaonderwijsScrum in informaticaonderwijs
Scrum in informaticaonderwijs
 
Saas: Software AND Service
Saas: Software AND ServiceSaas: Software AND Service
Saas: Software AND Service
 
Service Analysis And Design
Service Analysis And DesignService Analysis And Design
Service Analysis And Design
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Contract First Modeling Services Using Uml
Contract First Modeling Services Using UmlContract First Modeling Services Using Uml
Contract First Modeling Services Using Uml
 

Dernier

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Dernier (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Ajax And JSON

  • 1. AJAX CRIA Webtechnology Thursday, March 18, 2010
  • 2. Some applications of AJAX 2  Validation  Dynamic listboxes  Autorefresh  Excessive tooltips  Calling webservices CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 3. AJAX 3  Asynchronous Javascript And XML  No DOM Standard, equals implementation in several browsers through the XMLHttpRequest CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 4. XMLHttpRequest 4 AJAX Enabled Web App. Webserver Server Resource XHR function callback() { 2 } Databaseserver event DB CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 5. XMLHttpRequest 4 AJAX Enabled Web App. Webserver Server Resource XHR function callback() { 2 } Databaseserver 1 DB event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 6. XMLHttpRequest 4 AJAX Enabled Web App. Webserver 3 Server Resource XHR function callback() { 2 } Databaseserver 1 DB event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 7. XMLHttpRequest 4 AJAX Enabled Web App. Webserver 3 Server Resource XHR function callback() { 4 2 } Databaseserver 1 DB event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 8. XMLHttpRequest 4 AJAX Enabled Web App. Webserver 3 Server Resource XHR 5 function callback() { 4 2 } Databaseserver 1 DB event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 9. XMLHttpRequest 4 AJAX Enabled Web App. Webserver 3 Server Resource XHR 5 function callback() { 4 2 } 6 Databaseserver 1 DB event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 10. XMLHttpRequest 5 HTML: <div id="emailSection"> <input id="email" type="text" onblur="new ValidationServiceRequestor().validateEmail();"/> <label>Emailadres</label> </div> JAVASCRIPT: var ValidationServiceRequestor = function(){ this.validateEmail = function(){ var emailaddress = document.getElementById("email"); var serviceProxy = new ValidationServiceProxy(this); serviceProxy.validateEmail(emailaddress); } this.setValid = function(isValid){ alert(isValid) } } CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 11. XMLHttpRequest 6 var ValidationServiceProxy = function(callbackObject){ this.validateEmail = function(emailaddress){ validateEmailRequest = getXmlHttpRequestObject(); if (validateEmailRequest.readyState == 4 || validateEmailRequest.readyState == 0) { var params = "method=validateEmail&emailaddress=" + emailaddress.value; validateEmailRequest.open("GET", 'validationService.php?' + params, true); validateEmailRequest.onreadystatechange = validateEmailResponse; validateEmailRequest.send(null); } } validateEmailResponse = function(){ if (validateEmailRequest.readyState == 4) { var isEmailValid = eval("(" + validateEmailRequest.responseText + ")"); var isValid = (isEmailValid[0].emailaddressCount == 0) callbackObject.setValid(isValid) } } getXmlHttpRequestObject = function(){ if (window.XMLHttpRequest) { return new XMLHttpRequest(); } else { if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } } } } CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 12. XMLHttpRequest - Callback 7 function callback() { if (xmlHttp.readyState == 4) { if (xmlHttp.status == 200) { //do something interesting here } } } CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 13. XMLHttpRequest 8  You aren't allowed to make XMLHttpRequests to any server except the server where your web page came from. CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 14. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy Server Resource XHR function callback() { 2 } Webserver in other domain event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 15. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy Server Resource XHR function callback() { 2 } Webserver in other domain 1 event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 16. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy 3 Server Resource XHR function callback() { 2 } Webserver in other domain 1 event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 17. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy 3 Server Resource XHR function callback() { 4 2 } Webserver in other domain 1 event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 18. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy 3 Server Resource XHR 5 function callback() { 4 2 } Webserver in other domain 1 event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 19. XMLHttpRequest: Application Proxy 9 AJAX Enabled Web App. Webserver: Application Proxy 3 Server Resource XHR 5 function callback() { 4 2 } 6 Webserver in other domain 1 event WebService CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 20. On Demand JavaScript 10 Web App. Webserver in other domain Server Resource <script> </script> returns js 2 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 21. On Demand JavaScript 10 Web App. Webserver in other domain Server Resource <script> </script> returns js 2 1 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 22. On Demand JavaScript 10 Web App. Webserver in other domain 3 Server Resource <script> </script> returns js 2 1 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 23. On Demand JavaScript 10 Web App. Webserver in other domain 3 Server Resource <script> </script> returns js 2 4 1 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 24. On Demand JavaScript 10 Web App. Webserver in other domain 3 Server Resource <script> </script> returns js 5 2 4 1 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 25. On Demand JavaScript 10 Web App. Webserver in other domain <script id="external_script" 3 type="text/JavaScript"> Server </script> Resource <script> </script> <script> returns js 5 document.getElementById('external_script').src = 'http://cross.domain.com/other.js'; 4 2 </script> 1 event WebService http://ajaxpatterns.org/On-Demand_Javascript CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 26. XML AND JSON Thursday, March 18, 2010
  • 27. XML vs JSON 12 XML JSON <employee> var employee = { <firstName>John</firstName> "firstName" : John <lastName>Doe</lastName> , "lastName" : Doe <empNr>123</empNr> , "empNr" : 123 <title>Accountant</title> , "title" : "Accountant" </employee> } CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 28. JSON Is Not... 13  JSON is not a document format.  JSON is not a markup language.  JSON is not a general serialization format.  No recursive/recurring structures.  No invisible structures.  No functions. CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 29. Object 14 { "name": "Jack B. Nimble", "at large": true, "grade": "A", "format": { "type": "rect", "width": 1920, "height": 1080, "interlace": false, "framerate": 24 } } CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 30. JSON in Ajax 15  XMLHttpRequest  Obtain responseText  Parse the responseText  responseData = eval(  '(' + responseText + ')');  responseData =  responseText.parseJSON(); CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 31. Security 16  Is it safe to use eval with XMLHttpRequest?  The JSON data comes from the same server that vended the page. An eval of the data is no less secure than the original html.  If in doubt, use string.parseJSON instead of eval. CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 32. JSON Is Not XML 17  objects  element  arrays  attribute  strings  attribute string  numbers  content  booleans  <![CDATA[ ]]>  null  entities  declarations  schema  stylesheets  comments  version  namespace CRIA WT - Rody Middelkoop Thursday, March 18, 2010
  • 33. Server-side JSON 18 <?php $emailaddresses = getDataFromDataSource( "SELECT COUNT(*) AS emailaddressCount from adresboek where emailaddress = '" . $_REQUEST["emailaddress"] ."'"); $emailaddressesForJSON = array(); while( $row = mysql_fetch_array($emailaddresses)) { array_push($emailaddressesForJSON, $row); } $jsonText = json_encode( $emailaddressesForJSON ); echo $jsonText; function getDataFromDataSource($query) { mysql_connect("127.0.0.1", "root", "root") or die("Connection Failure to Database"); mysql_select_db("criademo") or die ("Database criademo not found."); $result = mysql_query($query); return $result; } ?> CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 34. Who is responsible for the right 19 format? Web App. Webserver WebService Client event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 35. Who is responsible for the right 19 format? Web App. Webserver WebService Client 1 event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 36. Who is responsible for the right 19 format? Web App. Webserver 2 WebService Client 1 event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 37. Who is responsible for the right 19 format? Web App. Webserver 2 WebService Client 3 1 event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 38. Who is responsible for the right 19 format? Web App. Webserver 2 WebService Client 3 1.SOAP: returns XML 2.REST: let the client pick a 1 format like XML, JSON, HTML event CRIA-WT - Rody Middelkoop Thursday, March 18, 2010
  • 39. Resources and a big thank you 20  JSON the x in AJAX, www.json.org/json.pdf  CRIA-WT - Rody Middelkoop Thursday, March 18, 2010