Creating Dynamic Webpages

Slides:



Advertisements
Similar presentations
JavaScript and AJAX Jonathan Foss University of Warwick
Advertisements

JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
JQUERY/AJAX ALIREZA KHATAMIAN DELARAM YAZDANSEPAS.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
Chapter 9 Introduction to the Document Object Model (DOM) JavaScript, Third Edition.
CS428 Web Engineering Lecture 15 Introduction to Jquery.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
Anatomy of an App HTML, CSS, jQuery, jQuery Mobile CIS 136 Building Mobile Apps 1.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
Agenda What is AJAX? What is jQuery? Demonstration/Tutorial Resources Q&A.
JQuery CS 268. What is jQuery? From their web site:
M. Taimoor Khan Courtesy: Norman White.
PhpXperts What is jQuery Javascript Library Fast and concise Simplifies the interaction between HTML and JavaScript.
Introduction to AJAX AJAX Keywords: JavaScript and XML
Nguyen Ich Cuong.  Course duration: 45’  Purpose: Present Introduction to JQuery  Targeted attendees: NICorp Trainee  Tests/quiz: Yes - 10’
JavaScript & jQuery the missing manual Chapter 11
CS 4720 RESTfulness and AJAX CS 4720 – Web & Mobile Systems.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
ASP.NET + Ajax Jesper Tørresø ITNET2 F08. Ajax Ajax (Asynchronous JavaScript and XML) A group of interrelated web development techniques used for creating.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
Jquery Nasrullah. Jquery jQuery is a JavaScript Library. jQuery greatly simplifies JavaScript programming. jQuery is easy to learn.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
CHAPTER 5 jQuery อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
JavaScript Library. What is jQuery jQuery is a lightweight JavaScript library. The purpose is to make it easier to use JavaScript code on your website.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Web Programming Language Week 9 Dr. Ken Cosh Introducing jQuery.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Intro to jQuery. What is jQuery? A JavaScript library Lightweight (about 31KB for the minified version) Simplifies HTML document traversing (DOM), event.
IS2802 Introduction to Multimedia Applications for Business Lecture 07: Introduction to jQuery Rob Gleasure
Unit 13 –JQuery Basics Instructor: Brent Presley.
Web Programming JAvaScript Ajax Programming Web Programming /38.
CHAPTER 13 COMMUNICATING WITH AJAX. LEARNING OBJECTIVES AJAX, which stands for Asynchronous JavaScript and XMLprovides a way for a browser to send and.
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
Web Technologies Lecture 8 JQuery. “A fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax.
AJAX and REST. Slide 2 What is AJAX? It’s an acronym for Asynchronous JavaScript and XML Although requests need not be asynchronous It’s not really a.
Dave Salinas. What is XML? XML stands for eXtensible Markup Language Markup language, like HTML HTML was designed to display data, whereas XML was designed.
AJAX AJAX Asynchronous JavaScript and XML --- MADHAVI
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
Introduction to JQuery COGS 187A – Fall JQuery jQuery is a JavaScript library, and allows us to manipulate HTML and CSS after the page has been.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
KAPITA SELEKTA INFORMATIKA Lasmedi Afuan, ST.M.Cs.
Introduction to JavaScript LIS390W1A Web Technologies and Techniques 24 Oct M. Cameron Jones.
JQuery Tutorial. What is jQuery jQuery is a JavaScript Library The purpose of jQuery is to make it much easier to use JavaScript on your website JavaScript.
JQuery is a fast, small, and feature-rich javascript library. It makes things like HTML document traversal and manipulation, event handling, animation,
What is jQuery?.
AJAX AJAX = Asynchronous JavaScript and XML.
Tek Raj Chhetri Code for Humans not for machine.
Introduction to Web programming
JQuery Basics 소속 / 작성자 이 문서는 나눔글꼴로 작성되었습니다. 설치하기.
AJAX.
AJAX.
The Cliff Notes Version
Prepared for Md. Zakir Hossain Lecturer, CSE, DUET Prepared by Miton Chandra Datta
Session V HTML5 APIs - AJAX & JSON
JQuery with ASP.NET.
HTML5 AJAX & JSON APIs
..
Secure Web Programming
MIS JavaScript and API Workshop (Part 3)
E-commerce Applications Development
Document Object Model.
Introduction to AJAX and JSON
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
PHP and JSON Topics Review JSON.
AJAX By Prof. B.A.Khivsara
Presentation transcript:

Creating Dynamic Webpages JavaScript & jQuery Creating Dynamic Webpages

About jQuery “Write less, do more.” MIT License Great cross-platform support (1.x more widely supported than 2.x)

Browser Support jQuery jQuery UI

Interacting with the Page Selectors and Accessors

The jQuery syntax is made for selecting HTML elements and performing some action on the elements. Basic syntax is: $(selector).action() A $ sign to define/access jQuery A (selector) to "query (or find)" HTML elements A jQuery action() to be performed on the element(s)

Selectors Selectors are used to tell JavaScript & jQuery which element(s) you are interested in working with Selectors follow the same pattern for jQuery as for CSS

Examples: $(this).hide() - hides the current element $("p").hide() - hides all <p> elements $(".test").hide() - hides all elements with class=“test” $("#test").hide() - hides the element with id=“test”

What Can jQuery do For You? JavaScript JQuery Cumbersome syntax Returns DOM objects Minimal code required Returns jQuery object (wraps DOM and adds functionality & convenience)

JS vs jQuery JavaScript jQuery <div class="interactive" id="body"> Body Content </div> #body .interactive <div class="interactive" id="footer"> Footer Content </div> #footer .interactive JavaScript jQuery //Returns the body div document.getElementById("body"); //Returns both divs (both participate in the "interactive" class) document.getElementsByClassName("interactive"); //Returns the body div $("#body"); //Returns both divs (both participate in the "interactive" class) $(".interactive");

JavaScript Selection Methods document.getElementById("myID");. document.getElementsByClassName("myName"); document.getElementsByName("myName"); document.getElementsByTagName("div"); document.querySelector(“#id"); document.querySelectorAll(“.class");

jQuery Selection Methods $("Any pattern and/or combination of selectors you feel like"); http://www.w3schools.com/jquery/jquery_ref_selectors.asp

Accessors JavaScript jQuery Get an object’s HTML var html = document.getElementById(“myElement”).inner HTML; Set an object’s HTML document.getElementById(“#myElement”).inne rHTML = “<span> Display this HTML </span>"; Get an object’s value var text = document.getElementById(“myElement”).value ; Set an object’s value document.getElementById(“myElement”).value = "Display this string"; Get an object’s HTML var html = $(“#myElement”).html(); Set an object’s HTML $(“#myElement”).html(“<span> Display this HTML</span>"); Get an object’s text var text = $(“#myElement”).text(); Set an object’s text $(“#myElement”).text("Display this string"); Get an object’s value var value = $(“#myElement”).val(); Set an object’s value $(“#myElement”).val("Display this string");

$().text(); From jQuery Documentation @ http://www.jQuery.com/

Document Ready Event $(document).ready(function(){    // jQuery methods go here... });

Example: $(document).ready(function(){     $("button").on(“click”,function(){         $("p").hide();     }); }); Mouse events - .click, .dblclick, .mouseenter, ….. Keyboard Events - .keypress, .keydown…….

<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("p").hide(); }); </head> <body> <h2>This is a heading</h2> <p>This is a paragraph.</p> <p>This is another paragraph.</p> <button>Click me</button> </body> </html>

jQuery prototyping All objects have a prototype property. It is simply an object from which other objects can inherit properties.

Example function Person(name) { this.name = name; } Person.prototype.sayHello = function () { alert(this.name + " says hello"); }; var james = new Person("James"); james.sayHello(); // Alerts "James says hello“

Explanation of Example In this example, Person is a constructor function. It can be instantiated by calling it with the new operator. Inside the constructor, the this keyword refers to the instance, so every instance has its own name property. The prototype of Person is shared between all instances. So all instances of Person have a sayHello method that they inherit from Person.prototype. By defining the sayHello method as a property of Person.prototype we are saving memory. We could just as easily give every instance of Person its own copy of the method (by assigning it to this.sayHello inside the constructor), but that's not as efficient.

Method chaining Method returns an object, allowing the calls to be chained together in a single statement without requiring variables to store the intermediate results jQuery relies heavily on chaining. This makes it easy to call several methods on the same selection

Java Public class DiaLog{ public DiaLog setTitle(String title){ //logic set title return this; } public DiaLog setMessage(String msg){ //logic set msg new Dialog().setTitle(“Title”).setMessage(“message”)

jQuery $(document). ready( function() { $(“li”). css(“color”,”blue”) jQuery $(document).ready( function() { $(“li”).css(“color”,”blue”) .slideUp(1000) .slideDown(1000) .attr(“title”,”my title”); } );

AJAX Asynchronous JavaScript and xml

What's AJAX? Group of web development techniques on the client side that enable the update of parts of page dynamically rather than requesting a whole page every time an event is triggered. Asynchronous means that your page can update any part without having to send an entire request for the whole page. JavaScript does the heavy lifting (handling events, server request and updating the page). uses XHR API for client server communication. It’s called AJAX, but the input format can be text, html, or json.

Why use AJAX More efficient way to transfer data. Less time spent on updating. Better user experience. Page is more dynamic and responsive.

Example <!DOCTYPE html> <html> <head> <script> function loadXMLDoc(url) { var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange=function() if (xmlhttp.readyState==4 && xmlhttp.status==200) document.getElementById('A1').innerHTML=xmlhttp.status; document.getElementById('A2').innerHTML=xmlhttp.statusText; document.getElementById('A3').innerHTML=xmlhttp.responseText; } xmlhttp.open("GET",url,true); xmlhttp.send(); </script> </head> <body> <h2>Retrieve data from XML file</h2> <p><b>Status:</b><span id="A1"></span></p> <p><b>Status text:</b><span id="A2"></span></p> <p><b>Response:</b><span id="A3"></span></p> <button onclick="loadXMLDoc('note.xml')">Get XML data</button> </body> </html>

JSON Objects A Brief Glossing

What is a JSON Object? A JSON object is an associative array (map/dictionary) that is machine and (arguably) human readable Commonly contains nested arrays/objects

What Does it Look Like? {"employees":[     {"firstName":"John", "lastName":"Doe"},     {"firstName":"Anna", "lastName":"Smith"},     {"firstName":"Peter", "lastName":"Jones"} ]}

References & Resources http://www.w3schools.com/js/js_object_prototypes.asp http://stackoverflow.com/questions/13140292/what-does- prototype-mean-here-in-the-jquery-source-code http://jquery.org/ http://jqueryui.com/ http://www.w3schools.com/js/ http://www.w3schools.com/jquery/ http://www.w3schools.com/json/