SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Downloaden Sie, um offline zu lesen
jQuery Makes Writing JavaScript
Fun Again

 Doris Chen Ph.D.
 Developer Evangelist
 Microsoft
 http://blogs.msdn.com/b/dorischen/
Who am I?
• Developer Evangelist at Microsoft based in Silicon Valley, CA
   – Blog: http://blogs.msdn.com/b/dorischen/
   – Twitter @doristchen
   – Email: doris.chen@microsoft.com
• Has over 13 years of experience in the software industry focusing on
  web technologies
• Spoke and published widely at JavaOne, O'Reilly, SD West, SD
  Forum and worldwide User Groups meetings
• Before joining Microsoft, Doris Chen was a Technology Evangelist at
  Sun Microsystems
• Doris received her Ph.D. from the University of California at Los
  Angeles (UCLA)
Agenda
• Essentials of jQuery
• New jQuery Plugins: Templates, DataLink,
  Globalization
• Working with OData, JSONP, Netflix
• Working with Web Services, Database and
  OData
• Summary
What is AJAX?
• Ajax= acronym for:
  > Asynchronous JavaScript And XML(or
    XMLHTTPRequest )
• Browser client uses JavaScript to
  Asynchronously get data from a server and
  update page dynamically without refreshing the
  whole page
• More interactive user experience
“Naked” Ajax is too complex
• A lot of JavaScript programming involved
  > “It is buggy and broken”
  > “Used for annoying people”
  > Difficult to debug and maintain
  > ...
• You need a deep understanding of Ajax
  techniques
• Have to handle all XmlHttpRequest interactions
  yourself
• Have to handle cross browser inconsistence
  yourself
Solutions
• JavaScript Toolkits
  > Wrap up ajax details in javascript libraries
  > jQuery, Dojo, prototype+scriptaculous, Yahoo,...
jQuery Adoption




http://trends.builtwith.com/javascript/JQuery
What is jQuery?
• Created by John Resig and first announced Jan 2006 at
  BarCampNYC
• Most popular JavaScript library in use today
  > simplifies the interaction between HTML and JavaScript
• Free, open source (MIT, GPL)
• Cross Browser
  > IE6+, FF2+, Sarari 3+, Chrome, Opera 9+
• Find it at http://jquery.com
• It’s a joy to use
Why jQuery ?
• Cross-browser compatibility
• Fast & Small
    – 24KB in size (Minified and Gzipped)
    – Core is minimum and add Plugins when
•    Short Learning curve & Great Documentation
•   Tons of Plug-in: jQuery plugin repository
•   CSS3 Selectors Compliant
•   Helpful Utilities
    – string trimming, easily extend objects, iteration, array
      manipulation, support function
• jQuery UI: jQuery User Interface
• Widespread Adoption
    – Google, Microsoft, Amazon, Twitter, Dell, Mozilla, Wordpress &
      Drupal, HP, IBM, Intel, Ruby on Rails
Getting Start
• Download jQuery at jquery.com
  – <script type="text/javascript" src="/js/jQuery. js"></script>
• Microsoft CDN or Google CDN
  – <script src="http://ajax.microsoft.com/ajax/jquery/jquery-
    1.4.2.js" type="text/javascript"></script>
  – <script type="text/javascript"
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jqu
    ery.js"></script>
jQuery Philosophy



Find someone        Do something to
  from HTML               it
   (selector)          (method)
Focus of jQuery
• Find someone in HTML and do something


      $(“div”).addClass(“header”)

• JQuery object
  > Commonly used “$”
  > Can also named “jQuery”


     jQuery(“div”).addClass(“header”)
Find Someone: Selector
• CSS Style
  –   $(“#myID”)              // by id
  –   $(“.myClass”)           // by class name
  –   $(“myTag”)              // by tag (element name)
  –   $(“#id, .class, tag”)   // multiple
• Hierarchy
  – $("form input")           // descendant
  – $("#main > *")            // child
  – $("#prev ~ div")          // sibling
• Form
  – $("form :radio")
  – $("#dvMainForm :checkbox")
  – $("input:disabled")
Do something with the found
               elements
• Attributes get/set
• Manipulation
• Events
• Effects
• AJAX
Attribute
•   $("em").attr("title")
•   $("label").html()
                                    Get
•   $("p:first").text()
•   $("input").val() • $("em").attr("title", "zupzip")
                      • $("label").html("zupzip")
      Set
                      • $("p:first").text("zupzip")
                      • $("input").val("zupzip")
Manipulation
• Apply css style dynamically
   – $(“#target”).addClass(“css_class”);
• Toggle css style
   – $(“#target”).toggleClass(“css_class”);
• Append
   – $("p").append("<strong>Hello</strong>");
• appendTo
   – $("span").appendTo("#foo");
• prepend &prependTo
• after
   – $("p").after("<b>Hello</b>");
• before
   – $("p").before("<b>Hello</b>"); Manipulations Demo
Events
• click, hover, change....
   $(“#target”).click(function(){....});
• bind
   $(“#target”).bind(“click”, function(){....});
• Chain event handlers
   $(“#target”).click(....).hover(...);

                                Events Demo
Effects
• Show and Hide
   – $(“#target”).show()
   – $(“#target”).hide()
• Fade in and out
   – $(“#target”).fadein()
   – $(“#target”).fadeout()
• Slide up and down
   – $(“#target”).slideup()
   – $(“#target”).slidedown()
• Custom animation              Animation Demo
AJAX
• load(url, [data], callback)
  > $(„#myContainer‟).load(„home/myHtmlSnippet‟);

• $.get(url, [data], callback)
• $.post(url, [data], callback)
• $.ajax(options)
  > $.ajax({
    type : “GET”
        url : “url”
        data : data
        success : callback
    });
jQuery Stack & Chaining
$(‘body’)        // [body]
  .find(‘p’) // [p, p, p] > [body]
     .find(‘a’) // [a, a] > [p, p, p] > [body]
.addClass(‘foo’)
     .end() // [p, p, p] > [body]
   .end()       // [body]

                                             20
jQuery Stack & Chaining

$(‘tr’)             //get all rows
 .filter(‘:odd’)    //get all odd rows
   .addClass(‘myOddClass’)
   .end()           //back to all rows
 .filter(‘:even’)   //get all even rows
     .addClass(‘myEvenClass’);

                                          21
Agenda
• Essentials of jQuery
• New jQuery Plugins: Templates, DataLink,
  Globalization
• Working with OData, JSONP, Netflix
• Working with Web Services, Database and
  OData
• Summary
Microsoft is Contributing to jQuery Library
• jQuery Templates plugin, Data Link plugin, and Globalization plugin have
  been accepted as officially supported plugins of the jQuery project
   – jQuery Templates (with jQuery 1.4.2) and Datalink plugins (with jQuery
       1.4.3) will be managed by the jQuery Core team
   – jQuery Globalization plugin will become part of the jQuery UI project
   – jQuery Templates plugin will be part of jQuery Core library 1.5
• API Documentation
   – jQuery Templates http://api.jquery.com/category/plugins/templates/
   – jQuery Data Link– http://api.jquery.com/category/plugins/data-link/
   – jQuery Globalization– Available soon
• Download
   – jQuery Templates – http://github.com/jquery/jquery-tmpl
   – jQuery Datalink – http://github.com/jquery/jquery-datalink
   – jQuery Globalization – http://github.com/jquery/jquery-global
• Full product support for jQuery
   – Ship with Visual Studio with Great Intellisense support
Templates Plugin (jQuery 1.4.2)
• create client templates
   – e.g. format a set of database records from the server
     through an Ajax request
    <body>
    <ul id="movieList"></ul>
    <script id="movieTemplate" type="text/x-jquery-tmpl">
      <li><b>${Name}</b> (${ReleaseYear})</li>
    </script>
    <script src="http://code.jquery.com/jquery-latest.min.js"></script>
    <script src="http://nje.github.com/jquery-tmpl/jquery.tmpl.js"></script>
    <script>
    var movies = [
       { Name: "The Red Violin", ReleaseYear: "1998" },
       { Name: "Eyes Wide Shut", ReleaseYear: "1999" },
       { Name: "The Inheritance", ReleaseYear: "1976" }
    ];
    $( "#movieTemplate" ).tmpl( movies )
       .appendTo( "#movieList" );
    </script> </body>
Datalink Plugin (jQuery 1.4.3)
• Easily keep user interface and data synchronized
   – automatically synchronize the input fields of a form with the
      properties of JavaScript product object
   <script src="http://github.com/nje/jquery-
   datalink/raw/e3e3be4312c9b224a8d9b25031f4ac876e4f70fd/jquery.js"></script>
    <script src="http://github.com/nje/jquery-datalink/raw/master/jQuery.datalink.js"></script>
   <form> <div>
       First Name: <input type="text" name="firstName" />
   </div></form>
     person.firstName: <span id="objFirst"></span><br/>
    <script>
     var person = {}; $("form").link(person);
     // Chain link the person object to these elements to show the results
     $("#objFirst").link(person, {
       firstName: {
          name: "objFirst",
          convertBack: function (value, source, target) {
             $(target).text(value);
          } } });
   $(person).data("firstName", "John");
   </script>
Globalization Plugin (jQuery 1.4.2)
• enables you to use different cultural
  conventions
• formatting or parsing numbers, dates and
  times, calendars, and currencies
• has information on over 350 cultures
• can use this plugin with the core jQuery library
  or plugins built on top of the jQuery library
Agenda
• Essentials of jQuery
• New jQuery Plugins: Templates, DataLink,
  Globalization
• Working with OData, JSONP, Netflix
• Working with Web Services, Database and
  OData
• Summary
Develop Netflix Movie Search Application using
jQuery, OData, JSONP and Netflix Technologies
                     JSONP Ajax Call

                       OData Query

                 http://odata.netflix.com/Catalo
                 g/Titles?$filter=Name%20eq%2      Netflix OData
                 0'Star%20Trek'                      Provider

                      OData in JSON
                 Callback Render on jQuery Template
OData
• Web protocol for querying and updating data
• Uniform way of representing structured data
   – Atom, JSON formats
• Uniform URL conventions
   – Navigation, filtering, sorting, paging, etc.
      • /Bookmarks?$orderby=Name        //sorting
      • /Bookmarks?$top=10&$skip=30     //paging
• Uniform operations
   – Addressability
   – GET, POST, PUT, DELETE
• http://www.odata.org/
Netflix OData in Atom
Netflix OData in Feeder Reading View
Netflix OData Diagram



          Query String


http://odata.netflix.com/Catalog/Titles?$filter
=Name%20eq%20'Star%20Trek'
Key Steps
•   Start with an empty HTML page
•   Define style or you can put it in a css file
•   Develop start up page
•   Define the template of the response page
•   Compose the JSONP call
•   Implement callback routine and using jQuery template
    – Microsoft has contributed jQuery template jquery.tmpl.js to
      jQuery project and it will be part jQuery in next release.
• Implement movie play using Netflix API
    – You need to apply a Netflix Developer API account and get the
      key.
    – More information http://developer.netflix.com/
Style
<head>
    <title>Search Movies</title>
    <style type="text/css">
        #movieTemplateContainer div
        {
            width:400px;
            padding: 10px;
            margin: 10px;
            border: black solid 1px;
        }
    </style>
</head>
Start Up Page and Template Result Page

<body>
<label>Search Movies:</label>
<input id="movieName" size="50" />
<button id="btnLookup">Lookup</button>

<div id="movieTemplateContainer"></div>

<script id="movieTemplate" type="text/x-jquery-tmpl">
  <div>
     <img src="${BoxArt.LargeUrl}" />
     <strong>${Name}</strong>
    <br/>
    <button id="playButton" movieID=${NetflixApiId}
      onclick="play(this)">Play Now</button>
    <p>
     {{html Synopsis}}
     </p>
  </div>
</script>
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="Scripts/jquery.tmpl.js"></script>
Make JSONP Call
<script type="text/javascript">
  $("#btnLookup").click(function () {

    // Build OData query
    var movieName = $("#movieName").val();
    var query = "http://odata.netflix.com/Catalog" // netflix base url
                   + "/Titles" // top-level resource
       + "?$filter=substringof('" + escape(movieName) + "',Name)" //filter by movie name
       + "&$callback=callback" // jsonp request
       + "&$format=json"; // json request
    // Make JSONP call to Netflix
  $.ajax({
        dataType: "jsonp",
        url: query,
        jsonpCallback: "callback",
        success: callback
        });
    });
Callback and Template

<div id="movieTemplateContainer"></div>
                                                    function callback(result) {
<script id="movieTemplate" type=" text/x-            // unwrap result
jquery-tmpl ">                                       var movies = result.d.results;
  <div>
      <img src="${BoxArt.LargeUrl}" />                $("#movieTemplateContainer")
     <strong>${Name}</strong>                    .empty();
     <br/>                                            $("#movieTemplate").tmpl(mov
     <button id="playButton" movieID=${Netflix   ies).appendTo("#movieTemplateCon
ApiId} onclick="play(this)">Play Now</button>    tainer");
    <p>                                            }
     {{html Synopsis}}
     </p>
  </div>
</script>
Netflix Movie Play
  function play(mvInfo) {
    var id = $(mvInfo).attr("movieID").substring(45);
     javascript: nflx.openPlayer('http://api.netflix.com/cat
alog/movie/'+id, 0, 0, ‘YOUR NETFLIX DEVELOPER ACCOUNT
KEY');
   }
</script>
<script src="http://jsapi.netflix.com/us/api/js/api.js"></sc
ript>

</body>
Agenda
• Essentials of jQuery
• New jQuery Plugins: Templates, DataLink,
  Globalization
• Working with OData, JSONP, Netflix
• Working with Web Services, Database and
  OData
• Summary
Developing jQuery Application
• Server Agnostic
• Server
   – Data Model: entity framework, JPA, etc
   – Develop Restful Web Services (OData Services)
• Client
   – Invoke Restful Web Services (OData Services)
   $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/MovieService.svc/Movies",
            data: data,
            dataType: "json",
            success: insertCallback
        });
   – Retrieve data and Present
        • JavaScript, jQuery, jQuery templates, jQuery plugins, HTML5
Favorite Movie Site Overview




Insert Data into Database




                            Displaying Movie List
Key Steps: Insert Data into Database
• Create ADO.NET Entity Data Model based on the
  DB
• Approach 1: Using generic handler
  – low-level approach to interacting with .NET through
    jQuery
  – Simple, just need jQuery library
• Approach 2: Using Ajax-enabled WCF Service
  – a little more work as need to serialize objects into JSON
• Approach 3 Using OData (WFC Data Service)
  – Taking advantage of open standards such as REST, JSON,
    and OData
  – The OData protocol (WCF Data Services) works very
    nicely with Ajax
     • quickly expose database data to an Ajax application
Create a Data Model
Approach 3: Create OData Service
Approach 3: Insert Data Using OData
                      Service
Create WCF Data Service (OData                            AddMovie.aspx
Service)                                                $("#btnAdd").click(function () {
public class MovieService : DataService<Movies               // Convert the form into an object
Entities>                                                    var data1 = { Title: $("#title1").val(), Genre: $("#g
   {// This method is called only once to initialize   enre").val(), ImageURL: $("#imageUrl").val() };
 service-wide policies.                                     // JSONify the data
      public static void InitializeService(DataServi         var data = JSON.stringify(data1);
ceConfiguration config)                                     // Post it
      {// TODO: set rules to indicate which entity           $.ajax({
sets and service operations are visible, updatabl                type: "POST",
e, etc.                                                          contentType: "application/json; charset=utf-8",
         // Examples:                                            url: "/MovieService.svc/Movies",
         config.SetEntitySetAccessRule("Movies",                 data: data,
EntitySetRights.All);                                            dataType: "json",
         // config.SetServiceOperationAccessRule(                success: insertCallback
"MyServiceOperation", ServiceOperationRights.                });
All);                                                      });
         config.DataServiceBehavior.MaxProtocolV          function insertCallback(result) {
ersion = DataServiceProtocolVersion.V2;                          var newMovie = result["d"];
      }                                                      // Show primary key
   }                                                         alert("Movie added with primary key " + newMov
                                                       ie.MovieID); }
Display Favorite Movies
• Retrieving movie list from OData
  – Approach 1: using jQuery and jQuery Plugin
    templates to create a table with pagination
  – Approach 2: using jQuery, jQuery Plugin templates
    and Element Stack Plugin to create a fun Movie list
     • http://www.marcofucci.com/tumblelog/15/mar/2010/
       elementstack_v1-1/
Agenda
• Essentials of jQuery
• New jQuery Plugins: Templates, DataLink,
  Globalization
• Working with OData, JSONP, Netflix
• Working with Web Services, Database and
  OData
• Summary
Summary
• jQuery is easy to learn and use
  – jQuery plugins, jQuery UI
• Microsoft is contributing to jQuery project
• jQuery can work with different server platform
  – Easy to produce and consume Restful Web
    Services, OData
Resources
• jquery.com Downloading
• api.jquery.com Documentation
• forum.jquery.com Community
• meetups.jquery.com Local Community
• plugins.jquery.com Extending
• jqueryui.com UI Widgets and Effects
• odata.org OData Services
Upcoming Web Camps
1 Day MVC and jQuery Web Camp
  Feb. 26th, 2011, Mountain View, CA
  March 25th, 2011, Seattle, WA
Free, learning innovative web technology,
hands on experience
  Detail and Registration http://bit.ly/gT9sBb
jQuery Makes Writing JavaScript
Fun Again

 Doris Chen Ph.D.
 doris.chen@microsoft.com
 Developer Evangelist
 Microsoft
 http://blogs.msdn.com/b/dorischen/

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)jeresig
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)jeresig
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuerymanugoel2003
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETJames Johnson
 
TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單偉格 高
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterpriseDave Artz
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETJames Johnson
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) ThemingPINGV
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)François Massart
 
Html5 Brown Bag
Html5 Brown BagHtml5 Brown Bag
Html5 Brown Bagstuplum
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupalBlackCatWeb
 
Client-side MVC with Backbone.js (reloaded)
Client-side MVC with Backbone.js (reloaded)Client-side MVC with Backbone.js (reloaded)
Client-side MVC with Backbone.js (reloaded)iloveigloo
 

Was ist angesagt? (20)

Jquery
JqueryJquery
Jquery
 
jQuery (MeshU)
jQuery (MeshU)jQuery (MeshU)
jQuery (MeshU)
 
jQuery (BostonPHP)
jQuery (BostonPHP)jQuery (BostonPHP)
jQuery (BostonPHP)
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
A Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NETA Rich Web experience with jQuery, Ajax and .NET
A Rich Web experience with jQuery, Ajax and .NET
 
TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單TOSSUG HTML5 讀書會 新標籤與表單
TOSSUG HTML5 讀書會 新標籤與表單
 
jQuery in the [Aol.] Enterprise
jQuery in the [Aol.] EnterprisejQuery in the [Aol.] Enterprise
jQuery in the [Aol.] Enterprise
 
A Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NETA Rich Web Experience with jQuery, Ajax and .NET
A Rich Web Experience with jQuery, Ajax and .NET
 
Grok Drupal (7) Theming
Grok Drupal (7) ThemingGrok Drupal (7) Theming
Grok Drupal (7) Theming
 
HTML5, just another presentation :)
HTML5, just another presentation :)HTML5, just another presentation :)
HTML5, just another presentation :)
 
Html5 Brown Bag
Html5 Brown BagHtml5 Brown Bag
Html5 Brown Bag
 
J query module1
J query module1J query module1
J query module1
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Echo HTML5
Echo HTML5Echo HTML5
Echo HTML5
 
jQuery and_drupal
jQuery and_drupaljQuery and_drupal
jQuery and_drupal
 
Client-side MVC with Backbone.js (reloaded)
Client-side MVC with Backbone.js (reloaded)Client-side MVC with Backbone.js (reloaded)
Client-side MVC with Backbone.js (reloaded)
 

Andere mochten auch

Database Project for Netflix (SQL Project)
Database Project for Netflix (SQL Project)Database Project for Netflix (SQL Project)
Database Project for Netflix (SQL Project)Dongqi Wang
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQueryKnoldus Inc.
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesSimon Willison
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Doris Chen
 
Ronalao termpresent
Ronalao termpresentRonalao termpresent
Ronalao termpresentElma Belitz
 
How to make advance rubik's cube power point slides and ppt diagram templates...
How to make advance rubik's cube power point slides and ppt diagram templates...How to make advance rubik's cube power point slides and ppt diagram templates...
How to make advance rubik's cube power point slides and ppt diagram templates...SlideTeam.net
 
Presentation to ESPN about the Netflix API
Presentation to ESPN about the Netflix APIPresentation to ESPN about the Netflix API
Presentation to ESPN about the Netflix APIDaniel Jacobson
 
3d cube building cube by cube powerpoint ppt slides.
3d cube building cube by cube powerpoint ppt slides.3d cube building cube by cube powerpoint ppt slides.
3d cube building cube by cube powerpoint ppt slides.SlideTeam.net
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery PresentationRod Johnson
 
Javascript State of the Union 2015 - English
Javascript State of the Union 2015 - EnglishJavascript State of the Union 2015 - English
Javascript State of the Union 2015 - EnglishHuge
 
Business Intelligence Presentation (1/2)
Business Intelligence Presentation (1/2)Business Intelligence Presentation (1/2)
Business Intelligence Presentation (1/2)Bernardo Najlis
 
Business intelligence ppt
Business intelligence pptBusiness intelligence ppt
Business intelligence pptsujithkylm007
 

Andere mochten auch (16)

Database Project for Netflix (SQL Project)
Database Project for Netflix (SQL Project)Database Project for Netflix (SQL Project)
Database Project for Netflix (SQL Project)
 
Jquery- One slide completing all JQuery
Jquery- One slide completing all JQueryJquery- One slide completing all JQuery
Jquery- One slide completing all JQuery
 
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript librariesJazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
Jazz up your JavaScript: Unobtrusive scripting with JavaScript libraries
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016
 
Ronalao termpresent
Ronalao termpresentRonalao termpresent
Ronalao termpresent
 
How to make advance rubik's cube power point slides and ppt diagram templates...
How to make advance rubik's cube power point slides and ppt diagram templates...How to make advance rubik's cube power point slides and ppt diagram templates...
How to make advance rubik's cube power point slides and ppt diagram templates...
 
Presentation to ESPN about the Netflix API
Presentation to ESPN about the Netflix APIPresentation to ESPN about the Netflix API
Presentation to ESPN about the Netflix API
 
3D Cubes for PowerPoint
3D Cubes for PowerPoint3D Cubes for PowerPoint
3D Cubes for PowerPoint
 
3d cube building cube by cube powerpoint ppt slides.
3d cube building cube by cube powerpoint ppt slides.3d cube building cube by cube powerpoint ppt slides.
3d cube building cube by cube powerpoint ppt slides.
 
jQuery
jQueryjQuery
jQuery
 
jQuery Presentation
jQuery PresentationjQuery Presentation
jQuery Presentation
 
Javascript State of the Union 2015 - English
Javascript State of the Union 2015 - EnglishJavascript State of the Union 2015 - English
Javascript State of the Union 2015 - English
 
Business Intelligence Presentation (1/2)
Business Intelligence Presentation (1/2)Business Intelligence Presentation (1/2)
Business Intelligence Presentation (1/2)
 
Business intelligence ppt
Business intelligence pptBusiness intelligence ppt
Business intelligence ppt
 
What is Big Data?
What is Big Data?What is Big Data?
What is Big Data?
 
Big data ppt
Big  data pptBig  data ppt
Big data ppt
 

Ähnlich wie jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)

SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQueryMark Rackley
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointMark Rackley
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014Mark Rackley
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationSean Burgess
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)jeresig
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)jeresig
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)David Giard
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and ModernizrJussi Pohjolainen
 
J query presentation
J query presentationJ query presentation
J query presentationakanksha17
 
J query presentation
J query presentationJ query presentation
J query presentationsawarkar17
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Julie Meloni
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQueryAlek Davis
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile IntroGonzalo Parra
 

Ähnlich wie jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group) (20)

bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
 
bcgr3-jquery
bcgr3-jquerybcgr3-jquery
bcgr3-jquery
 
Jquery fundamentals
Jquery fundamentalsJquery fundamentals
Jquery fundamentals
 
SPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuerySPTechCon DevDays - SharePoint & jQuery
SPTechCon DevDays - SharePoint & jQuery
 
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePointSPTechCon Boston 2015 - Utilizing jQuery in SharePoint
SPTechCon Boston 2015 - Utilizing jQuery in SharePoint
 
SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014SharePoint & jQuery Guide - SPSNashville 2014
SharePoint & jQuery Guide - SPSNashville 2014
 
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD CombinationLotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
Lotusphere 2012 Speedgeeking - jQuery & Domino, a RAD Combination
 
Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)Introduction to jQuery (Ajax Exp 2007)
Introduction to jQuery (Ajax Exp 2007)
 
JQuery UI
JQuery UIJQuery UI
JQuery UI
 
Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)Introduction to jQuery (Ajax Exp 2006)
Introduction to jQuery (Ajax Exp 2006)
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)How I Learned to Stop Worrying and Love jQuery (Jan 2013)
How I Learned to Stop Worrying and Love jQuery (Jan 2013)
 
Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
J query presentation
J query presentationJ query presentation
J query presentation
 
J query presentation
J query presentationJ query presentation
J query presentation
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)Learning About JavaScript (…and its little buddy, JQuery!)
Learning About JavaScript (…and its little buddy, JQuery!)
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
Mume JQueryMobile Intro
Mume JQueryMobile IntroMume JQueryMobile Intro
Mume JQueryMobile Intro
 

Mehr von Doris Chen

Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work EverywhereDoris Chen
 
Angular mobile angular_u
Angular mobile angular_uAngular mobile angular_u
Angular mobile angular_uDoris Chen
 
Lastest Trends in Web Development
Lastest Trends in Web DevelopmentLastest Trends in Web Development
Lastest Trends in Web DevelopmentDoris Chen
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Doris Chen
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...Doris Chen
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterDoris Chen
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Doris Chen
 
What Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS AppsWhat Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS AppsDoris Chen
 
Windows 8 Opportunity
Windows 8 OpportunityWindows 8 Opportunity
Windows 8 OpportunityDoris Chen
 
Wins8 appfoforweb fluent
Wins8 appfoforweb fluentWins8 appfoforweb fluent
Wins8 appfoforweb fluentDoris Chen
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Doris Chen
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsDoris Chen
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Doris Chen
 
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Doris Chen
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Doris Chen
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
Dive Into HTML5
Dive Into HTML5Dive Into HTML5
Dive Into HTML5Doris Chen
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It TodayDoris Chen
 
HTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and DesktopHTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and DesktopDoris Chen
 

Mehr von Doris Chen (20)

Building Web Sites that Work Everywhere
Building Web Sites that Work EverywhereBuilding Web Sites that Work Everywhere
Building Web Sites that Work Everywhere
 
Angular mobile angular_u
Angular mobile angular_uAngular mobile angular_u
Angular mobile angular_u
 
Lastest Trends in Web Development
Lastest Trends in Web DevelopmentLastest Trends in Web Development
Lastest Trends in Web Development
 
Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!Angular or Backbone: Go Mobile!
Angular or Backbone: Go Mobile!
 
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...OSCON Presentation: Developing High Performance Websites and Modern Apps with...
OSCON Presentation: Developing High Performance Websites and Modern Apps with...
 
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps FasterPractical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
Practical Performance Tips and Tricks to Make Your HTML/JavaScript Apps Faster
 
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5Developing High Performance Websites and Modern Apps with JavaScript and HTML5
Developing High Performance Websites and Modern Apps with JavaScript and HTML5
 
What Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS AppsWhat Web Developers Need to Know to Develop Native HTML5/JS Apps
What Web Developers Need to Know to Develop Native HTML5/JS Apps
 
Windows 8 Opportunity
Windows 8 OpportunityWindows 8 Opportunity
Windows 8 Opportunity
 
Wins8 appfoforweb fluent
Wins8 appfoforweb fluentWins8 appfoforweb fluent
Wins8 appfoforweb fluent
 
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
Develop High Performance Windows 8 Application with HTML5 and JavaScriptHigh ...
 
What Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 AppsWhat Web Developers Need to Know to Develop Windows 8 Apps
What Web Developers Need to Know to Develop Windows 8 Apps
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
 
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Windows 8 apps with JavaScript, HTML5 & CSS3
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
Building Beautiful and Interactive Metro apps with JavaScript, HTML5 & CSS3
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
Dive Into HTML5
Dive Into HTML5Dive Into HTML5
Dive Into HTML5
 
Practical HTML5: Using It Today
Practical HTML5: Using It TodayPractical HTML5: Using It Today
Practical HTML5: Using It Today
 
HTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and DesktopHTML 5 Development for Windows Phone and Desktop
HTML 5 Development for Windows Phone and Desktop
 

jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)

  • 1. jQuery Makes Writing JavaScript Fun Again Doris Chen Ph.D. Developer Evangelist Microsoft http://blogs.msdn.com/b/dorischen/
  • 2. Who am I? • Developer Evangelist at Microsoft based in Silicon Valley, CA – Blog: http://blogs.msdn.com/b/dorischen/ – Twitter @doristchen – Email: doris.chen@microsoft.com • Has over 13 years of experience in the software industry focusing on web technologies • Spoke and published widely at JavaOne, O'Reilly, SD West, SD Forum and worldwide User Groups meetings • Before joining Microsoft, Doris Chen was a Technology Evangelist at Sun Microsystems • Doris received her Ph.D. from the University of California at Los Angeles (UCLA)
  • 3. Agenda • Essentials of jQuery • New jQuery Plugins: Templates, DataLink, Globalization • Working with OData, JSONP, Netflix • Working with Web Services, Database and OData • Summary
  • 4. What is AJAX? • Ajax= acronym for: > Asynchronous JavaScript And XML(or XMLHTTPRequest ) • Browser client uses JavaScript to Asynchronously get data from a server and update page dynamically without refreshing the whole page • More interactive user experience
  • 5. “Naked” Ajax is too complex • A lot of JavaScript programming involved > “It is buggy and broken” > “Used for annoying people” > Difficult to debug and maintain > ... • You need a deep understanding of Ajax techniques • Have to handle all XmlHttpRequest interactions yourself • Have to handle cross browser inconsistence yourself
  • 6. Solutions • JavaScript Toolkits > Wrap up ajax details in javascript libraries > jQuery, Dojo, prototype+scriptaculous, Yahoo,...
  • 8. What is jQuery? • Created by John Resig and first announced Jan 2006 at BarCampNYC • Most popular JavaScript library in use today > simplifies the interaction between HTML and JavaScript • Free, open source (MIT, GPL) • Cross Browser > IE6+, FF2+, Sarari 3+, Chrome, Opera 9+ • Find it at http://jquery.com • It’s a joy to use
  • 9. Why jQuery ? • Cross-browser compatibility • Fast & Small – 24KB in size (Minified and Gzipped) – Core is minimum and add Plugins when • Short Learning curve & Great Documentation • Tons of Plug-in: jQuery plugin repository • CSS3 Selectors Compliant • Helpful Utilities – string trimming, easily extend objects, iteration, array manipulation, support function • jQuery UI: jQuery User Interface • Widespread Adoption – Google, Microsoft, Amazon, Twitter, Dell, Mozilla, Wordpress & Drupal, HP, IBM, Intel, Ruby on Rails
  • 10. Getting Start • Download jQuery at jquery.com – <script type="text/javascript" src="/js/jQuery. js"></script> • Microsoft CDN or Google CDN – <script src="http://ajax.microsoft.com/ajax/jquery/jquery- 1.4.2.js" type="text/javascript"></script> – <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jqu ery.js"></script>
  • 11. jQuery Philosophy Find someone Do something to from HTML it (selector) (method)
  • 12. Focus of jQuery • Find someone in HTML and do something $(“div”).addClass(“header”) • JQuery object > Commonly used “$” > Can also named “jQuery” jQuery(“div”).addClass(“header”)
  • 13. Find Someone: Selector • CSS Style – $(“#myID”) // by id – $(“.myClass”) // by class name – $(“myTag”) // by tag (element name) – $(“#id, .class, tag”) // multiple • Hierarchy – $("form input") // descendant – $("#main > *") // child – $("#prev ~ div") // sibling • Form – $("form :radio") – $("#dvMainForm :checkbox") – $("input:disabled")
  • 14. Do something with the found elements • Attributes get/set • Manipulation • Events • Effects • AJAX
  • 15. Attribute • $("em").attr("title") • $("label").html() Get • $("p:first").text() • $("input").val() • $("em").attr("title", "zupzip") • $("label").html("zupzip") Set • $("p:first").text("zupzip") • $("input").val("zupzip")
  • 16. Manipulation • Apply css style dynamically – $(“#target”).addClass(“css_class”); • Toggle css style – $(“#target”).toggleClass(“css_class”); • Append – $("p").append("<strong>Hello</strong>"); • appendTo – $("span").appendTo("#foo"); • prepend &prependTo • after – $("p").after("<b>Hello</b>"); • before – $("p").before("<b>Hello</b>"); Manipulations Demo
  • 17. Events • click, hover, change.... $(“#target”).click(function(){....}); • bind $(“#target”).bind(“click”, function(){....}); • Chain event handlers $(“#target”).click(....).hover(...); Events Demo
  • 18. Effects • Show and Hide – $(“#target”).show() – $(“#target”).hide() • Fade in and out – $(“#target”).fadein() – $(“#target”).fadeout() • Slide up and down – $(“#target”).slideup() – $(“#target”).slidedown() • Custom animation Animation Demo
  • 19. AJAX • load(url, [data], callback) > $(„#myContainer‟).load(„home/myHtmlSnippet‟); • $.get(url, [data], callback) • $.post(url, [data], callback) • $.ajax(options) > $.ajax({ type : “GET” url : “url” data : data success : callback });
  • 20. jQuery Stack & Chaining $(‘body’) // [body] .find(‘p’) // [p, p, p] > [body] .find(‘a’) // [a, a] > [p, p, p] > [body] .addClass(‘foo’) .end() // [p, p, p] > [body] .end() // [body] 20
  • 21. jQuery Stack & Chaining $(‘tr’) //get all rows .filter(‘:odd’) //get all odd rows .addClass(‘myOddClass’) .end() //back to all rows .filter(‘:even’) //get all even rows .addClass(‘myEvenClass’); 21
  • 22. Agenda • Essentials of jQuery • New jQuery Plugins: Templates, DataLink, Globalization • Working with OData, JSONP, Netflix • Working with Web Services, Database and OData • Summary
  • 23. Microsoft is Contributing to jQuery Library • jQuery Templates plugin, Data Link plugin, and Globalization plugin have been accepted as officially supported plugins of the jQuery project – jQuery Templates (with jQuery 1.4.2) and Datalink plugins (with jQuery 1.4.3) will be managed by the jQuery Core team – jQuery Globalization plugin will become part of the jQuery UI project – jQuery Templates plugin will be part of jQuery Core library 1.5 • API Documentation – jQuery Templates http://api.jquery.com/category/plugins/templates/ – jQuery Data Link– http://api.jquery.com/category/plugins/data-link/ – jQuery Globalization– Available soon • Download – jQuery Templates – http://github.com/jquery/jquery-tmpl – jQuery Datalink – http://github.com/jquery/jquery-datalink – jQuery Globalization – http://github.com/jquery/jquery-global • Full product support for jQuery – Ship with Visual Studio with Great Intellisense support
  • 24. Templates Plugin (jQuery 1.4.2) • create client templates – e.g. format a set of database records from the server through an Ajax request <body> <ul id="movieList"></ul> <script id="movieTemplate" type="text/x-jquery-tmpl"> <li><b>${Name}</b> (${ReleaseYear})</li> </script> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script src="http://nje.github.com/jquery-tmpl/jquery.tmpl.js"></script> <script> var movies = [ { Name: "The Red Violin", ReleaseYear: "1998" }, { Name: "Eyes Wide Shut", ReleaseYear: "1999" }, { Name: "The Inheritance", ReleaseYear: "1976" } ]; $( "#movieTemplate" ).tmpl( movies ) .appendTo( "#movieList" ); </script> </body>
  • 25. Datalink Plugin (jQuery 1.4.3) • Easily keep user interface and data synchronized – automatically synchronize the input fields of a form with the properties of JavaScript product object <script src="http://github.com/nje/jquery- datalink/raw/e3e3be4312c9b224a8d9b25031f4ac876e4f70fd/jquery.js"></script> <script src="http://github.com/nje/jquery-datalink/raw/master/jQuery.datalink.js"></script> <form> <div> First Name: <input type="text" name="firstName" /> </div></form> person.firstName: <span id="objFirst"></span><br/> <script> var person = {}; $("form").link(person); // Chain link the person object to these elements to show the results $("#objFirst").link(person, { firstName: { name: "objFirst", convertBack: function (value, source, target) { $(target).text(value); } } }); $(person).data("firstName", "John"); </script>
  • 26. Globalization Plugin (jQuery 1.4.2) • enables you to use different cultural conventions • formatting or parsing numbers, dates and times, calendars, and currencies • has information on over 350 cultures • can use this plugin with the core jQuery library or plugins built on top of the jQuery library
  • 27. Agenda • Essentials of jQuery • New jQuery Plugins: Templates, DataLink, Globalization • Working with OData, JSONP, Netflix • Working with Web Services, Database and OData • Summary
  • 28. Develop Netflix Movie Search Application using jQuery, OData, JSONP and Netflix Technologies JSONP Ajax Call OData Query http://odata.netflix.com/Catalo g/Titles?$filter=Name%20eq%2 Netflix OData 0'Star%20Trek' Provider OData in JSON Callback Render on jQuery Template
  • 29. OData • Web protocol for querying and updating data • Uniform way of representing structured data – Atom, JSON formats • Uniform URL conventions – Navigation, filtering, sorting, paging, etc. • /Bookmarks?$orderby=Name //sorting • /Bookmarks?$top=10&$skip=30 //paging • Uniform operations – Addressability – GET, POST, PUT, DELETE • http://www.odata.org/
  • 31. Netflix OData in Feeder Reading View
  • 32. Netflix OData Diagram Query String http://odata.netflix.com/Catalog/Titles?$filter =Name%20eq%20'Star%20Trek'
  • 33. Key Steps • Start with an empty HTML page • Define style or you can put it in a css file • Develop start up page • Define the template of the response page • Compose the JSONP call • Implement callback routine and using jQuery template – Microsoft has contributed jQuery template jquery.tmpl.js to jQuery project and it will be part jQuery in next release. • Implement movie play using Netflix API – You need to apply a Netflix Developer API account and get the key. – More information http://developer.netflix.com/
  • 34. Style <head> <title>Search Movies</title> <style type="text/css"> #movieTemplateContainer div { width:400px; padding: 10px; margin: 10px; border: black solid 1px; } </style> </head>
  • 35. Start Up Page and Template Result Page <body> <label>Search Movies:</label> <input id="movieName" size="50" /> <button id="btnLookup">Lookup</button> <div id="movieTemplateContainer"></div> <script id="movieTemplate" type="text/x-jquery-tmpl"> <div> <img src="${BoxArt.LargeUrl}" /> <strong>${Name}</strong> <br/> <button id="playButton" movieID=${NetflixApiId} onclick="play(this)">Play Now</button> <p> {{html Synopsis}} </p> </div> </script> <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="Scripts/jquery.tmpl.js"></script>
  • 36. Make JSONP Call <script type="text/javascript"> $("#btnLookup").click(function () { // Build OData query var movieName = $("#movieName").val(); var query = "http://odata.netflix.com/Catalog" // netflix base url + "/Titles" // top-level resource + "?$filter=substringof('" + escape(movieName) + "',Name)" //filter by movie name + "&$callback=callback" // jsonp request + "&$format=json"; // json request // Make JSONP call to Netflix $.ajax({ dataType: "jsonp", url: query, jsonpCallback: "callback", success: callback }); });
  • 37. Callback and Template <div id="movieTemplateContainer"></div> function callback(result) { <script id="movieTemplate" type=" text/x- // unwrap result jquery-tmpl "> var movies = result.d.results; <div> <img src="${BoxArt.LargeUrl}" /> $("#movieTemplateContainer") <strong>${Name}</strong> .empty(); <br/> $("#movieTemplate").tmpl(mov <button id="playButton" movieID=${Netflix ies).appendTo("#movieTemplateCon ApiId} onclick="play(this)">Play Now</button> tainer"); <p> } {{html Synopsis}} </p> </div> </script>
  • 38. Netflix Movie Play function play(mvInfo) { var id = $(mvInfo).attr("movieID").substring(45); javascript: nflx.openPlayer('http://api.netflix.com/cat alog/movie/'+id, 0, 0, ‘YOUR NETFLIX DEVELOPER ACCOUNT KEY'); } </script> <script src="http://jsapi.netflix.com/us/api/js/api.js"></sc ript> </body>
  • 39.
  • 40. Agenda • Essentials of jQuery • New jQuery Plugins: Templates, DataLink, Globalization • Working with OData, JSONP, Netflix • Working with Web Services, Database and OData • Summary
  • 41. Developing jQuery Application • Server Agnostic • Server – Data Model: entity framework, JPA, etc – Develop Restful Web Services (OData Services) • Client – Invoke Restful Web Services (OData Services) $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "/MovieService.svc/Movies", data: data, dataType: "json", success: insertCallback }); – Retrieve data and Present • JavaScript, jQuery, jQuery templates, jQuery plugins, HTML5
  • 42. Favorite Movie Site Overview Insert Data into Database Displaying Movie List
  • 43. Key Steps: Insert Data into Database • Create ADO.NET Entity Data Model based on the DB • Approach 1: Using generic handler – low-level approach to interacting with .NET through jQuery – Simple, just need jQuery library • Approach 2: Using Ajax-enabled WCF Service – a little more work as need to serialize objects into JSON • Approach 3 Using OData (WFC Data Service) – Taking advantage of open standards such as REST, JSON, and OData – The OData protocol (WCF Data Services) works very nicely with Ajax • quickly expose database data to an Ajax application
  • 44. Create a Data Model
  • 45. Approach 3: Create OData Service
  • 46. Approach 3: Insert Data Using OData Service Create WCF Data Service (OData AddMovie.aspx Service) $("#btnAdd").click(function () { public class MovieService : DataService<Movies // Convert the form into an object Entities> var data1 = { Title: $("#title1").val(), Genre: $("#g {// This method is called only once to initialize enre").val(), ImageURL: $("#imageUrl").val() }; service-wide policies. // JSONify the data public static void InitializeService(DataServi var data = JSON.stringify(data1); ceConfiguration config) // Post it {// TODO: set rules to indicate which entity $.ajax({ sets and service operations are visible, updatabl type: "POST", e, etc. contentType: "application/json; charset=utf-8", // Examples: url: "/MovieService.svc/Movies", config.SetEntitySetAccessRule("Movies", data: data, EntitySetRights.All); dataType: "json", // config.SetServiceOperationAccessRule( success: insertCallback "MyServiceOperation", ServiceOperationRights. }); All); }); config.DataServiceBehavior.MaxProtocolV function insertCallback(result) { ersion = DataServiceProtocolVersion.V2; var newMovie = result["d"]; } // Show primary key } alert("Movie added with primary key " + newMov ie.MovieID); }
  • 47. Display Favorite Movies • Retrieving movie list from OData – Approach 1: using jQuery and jQuery Plugin templates to create a table with pagination – Approach 2: using jQuery, jQuery Plugin templates and Element Stack Plugin to create a fun Movie list • http://www.marcofucci.com/tumblelog/15/mar/2010/ elementstack_v1-1/
  • 48. Agenda • Essentials of jQuery • New jQuery Plugins: Templates, DataLink, Globalization • Working with OData, JSONP, Netflix • Working with Web Services, Database and OData • Summary
  • 49. Summary • jQuery is easy to learn and use – jQuery plugins, jQuery UI • Microsoft is contributing to jQuery project • jQuery can work with different server platform – Easy to produce and consume Restful Web Services, OData
  • 50. Resources • jquery.com Downloading • api.jquery.com Documentation • forum.jquery.com Community • meetups.jquery.com Local Community • plugins.jquery.com Extending • jqueryui.com UI Widgets and Effects • odata.org OData Services
  • 51. Upcoming Web Camps 1 Day MVC and jQuery Web Camp Feb. 26th, 2011, Mountain View, CA March 25th, 2011, Seattle, WA Free, learning innovative web technology, hands on experience Detail and Registration http://bit.ly/gT9sBb
  • 52. jQuery Makes Writing JavaScript Fun Again Doris Chen Ph.D. doris.chen@microsoft.com Developer Evangelist Microsoft http://blogs.msdn.com/b/dorischen/