Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains 2 components

Similar documents
Module 5 JavaScript, AJAX, and jquery. Module 5. Module 5 Contains an Individual and Group component

JavaScript, jquery & AJAX

TIME SCHEDULE MODULE TOPICS PERIODS. HTML Document Object Model (DOM) and javascript Object Notation (JSON)

User Interaction: jquery

AJAX: Introduction CISC 282 November 27, 2018

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

2/6/2012. Rich Internet Applications. What is Ajax? Defining AJAX. Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett

An Introduction to AJAX. By : I. Moamin Abughazaleh

A.A. 2008/09. What is Ajax?

AJAX(Asynchronous Javascript + XML) Creating client-side dynamic Web pages

XMLHttpRequest. CS144: Web Applications

Index. Boolean value, 282

Lesson 12: JavaScript and AJAX

Session 16. JavaScript Part 1. Reading

AJAX: The Basics CISC 282 March 25, 2014

Session 6. JavaScript Part 1. Reading

AJAX: The Basics CISC 282 November 22, 2017

CITS1231 Web Technologies. Ajax and Web 2.0 Turning clunky website into interactive mashups


This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

AJAX. Introduction. AJAX: Asynchronous JavaScript and XML

8/19/2018. Web Development & Design Foundations with HTML5. Learning Objectives (1 of 2) Learning Objectives (2 of 2) What is JavaScript?

Index. Ray Nicholus 2016 R. Nicholus, Beyond jquery, DOI /

Copyright Descriptor Systems, Course materials may not be reproduced in whole or in part without prior written consent of Joel Barnum

AJAX ASYNCHRONOUS JAVASCRIPT AND XML. Laura Farinetti - DAUIN

CISC 1600 Lecture 2.4 Introduction to JavaScript

Outline. Introduction to JavaScript Resources What is JavaScript? JavaScript in web pages

Web Programming Step by Step

,


AJAX Programming Chris Seddon

Client Side JavaScript and AJAX

Contents. Demos folder: Demos\14-Ajax. 1. Overview of Ajax. 2. Using Ajax directly. 3. jquery and Ajax. 4. Consuming RESTful services

INF5750. Introduction to JavaScript and Node.js

Module7: AJAX. Click, wait, and refresh user interaction. Synchronous request/response communication model. Page-driven: Workflow is based on pages

Outline. AJAX for Libraries. Jason A. Clark Head of Digital Access and Web Services Montana State University Libraries

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript Programming

Fall Semester (081) Module7: AJAX

AJAX. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

JavaScript CS 4640 Programming Languages for Web Applications

UNIT 3 SECTION 1 Answer the following questions Q.1: What is an editor? editor editor Q.2: What do you understand by a web browser?

Session 11. Ajax. Reading & Reference

Client-side Debugging. Gary Bettencourt

AJAX Workshop. Karen A. Coombs University of Houston Libraries Jason A. Clark Montana State University Libraries

Wakanda Architecture. Wakanda is made up of three main components: Wakanda Server Wakanda Studio Wakanda Client Framework

The course is supplemented by numerous hands-on labs that help attendees reinforce their theoretical knowledge of the learned material.

Web Development & Design Foundations with HTML5

BEFORE CLASS. If you haven t already installed the Firebug extension for Firefox, download it now from

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

5/19/2015. Objectives. JavaScript, Sixth Edition. Introduction to the World Wide Web (cont d.) Introduction to the World Wide Web

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

COURSE OUTLINE MOC 20480: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

Using Development Tools to Examine Webpages

Asynchronous JavaScript + XML (Ajax)

Session 18. jquery - Ajax. Reference. Tutorials. jquery Methods. Session 18 jquery and Ajax 10/31/ Robert Kelly,

Ajax- XMLHttpResponse. Returns a value such as ArrayBuffer, Blob, Document, JavaScript object, or a DOMString, based on the value of

CS7026. Introduction to jquery

Web Application Security

Intro To Javascript. Intro to Web Development

<form>. input elements. </form>

Working with Javascript Building Responsive Library apps

CodeValue. C ollege. Prerequisites: Basic knowledge of web development and especially JavaScript.

CSC Javascript

Comprehensive AngularJS Programming (5 Days)

JavaScript: Introduction, Types

Introduction to AJAX Bringing Interactivity & Intuitiveness Into Web Applications. By : Bhanwar Gupta SD-Team-Member Jsoft Solutions

Welcome to CS50 section! This is Week 10 :(

GRITS AJAX & GWT. Trey Roby. GRITS 5/14/09 Roby - 1

COMS W3101: SCRIPTING LANGUAGES: JAVASCRIPT (FALL 2017)

WebApp development. Outline. Web app structure. HTML basics. 1. Fundamentals of a web app / website. Tiberiu Vilcu

AJAX and PHP AJAX. Christian Wenz,

CGS 3066: Spring 2015 JavaScript Reference

HTML5 MOCK TEST HTML5 MOCK TEST I

Etanova Enterprise Solutions

The Discussion of Cross-platform Mobile Application Development Based on Phone Gap Method Limei Cui

JavaScript is described in detail in many books on the subject, and there is excellent tutorial material at

Jquery Manually Set Checkbox Checked Or Not

Programming in HTML5 with JavaScript and CSS3

10.1 Overview of Ajax

Javascript. Many examples from Kyle Simpson: Scope and Closures

AJAX: Rich Internet Applications

COURSE 20480B: PROGRAMMING IN HTML5 WITH JAVASCRIPT AND CSS3

footer, header, nav, section. search. ! Better Accessibility.! Cleaner Code. ! Smarter Storage.! Better Interactions.

E ECMAScript, 21 elements collection, HTML, 30 31, 31. Index 161

Programming in HTML5 with JavaScript and CSS3

Ajax. Ronald J. Glotzbach

Web Programming Paper Solution (Chapter wise)

Term Paper. P r o f. D r. E d u a r d H e i n d l. H o c h s c h u l e F u r t w a n g e n U n i v e r s i t y. P r e s e n t e d T o :

Jquery.ajax Call Returns Status Code Of 200 But Fires Jquery Error

CIW 1D CIW JavaScript Specialist.

CSE 154 LECTURE 26: JAVASCRIPT FRAMEWORKS

jquery and AJAX

JavaScript. jquery and other frameworks. Jacobo Aragunde Pérez. blogs.igalia.com/jaragunde

But before understanding the Selenium WebDriver concept, we need to know about the Selenium first.

Web 2.0 Käyttöliittymätekniikat

Web Design and Application Development

Sections and Articles

INTRODUCTION TO JAVASCRIPT

Transcription:

Module 5 JavaScript, AJAX, and jquery Module 5 Contains 2 components Both the Individual and Group portion are due on Monday October 30 th Start early on this module One of the most time consuming modules in the course Read the WIKI before starting along with a few JavaScript and jquery tutorials Extensible Networking Platform 1 1 - CSE 330 Creative Programming and Rapid Prototyping Module 5 JavaScript Scripting language to add interactivity to HTML pages Java and JavaScript are completely different languages AJAX Asynchronous JavaScript and XML (AJAX) Allows for retrieval of data from web servers in the background jquery JavaScript library Extensible Networking Platform 2 2 - CSE 330 Creative Programming and Rapid Prototyping

JavaScript Popular scripting language widely supported in browsers to add interaction Pop-Up Windows User Input Forms Calculations Special Effects Implementation of the ECMAScript language Extensible Networking Platform 3 3 - CSE 330 Creative Programming and Rapid Prototyping JavaScript JavaScript is a prototyped-based scripting language Dynamic, weakly typed Interpreted language You do not compile it Uses prototypes instead of classes for inheritance Extensible Networking Platform 4 4 - CSE 330 Creative Programming and Rapid Prototyping

Is JavaScript like Java? Java and JavaScript are similar like Car and Carpet are similar Two completely different languages with different concepts Java is compiled, JavaScript is interpreted Java is object-oriented, JavaScript is prototyped based Java requires strict typing, JavaScript allows for dynamic typing Extensible Networking Platform 5 5 - CSE 330 Creative Programming and Rapid Prototyping JavaScript Basics Declare a variable with var var foo = JS is fun ; Variables are objects Define a function with function function foo() { //Some JS code here } Functions are also objects Extensible Networking Platform 6 6 - CSE 330 Creative Programming and Rapid Prototyping

Writing a JavaScript Program JavaScript programs can either be placed directly into the HTML file or can be saved in external files You can place JavaScript anywhere within the HTML file: within the <HEAD> tags or the <BODY> tags Extensible Networking Platform 7 7 - CSE 330 Creative Programming and Rapid Prototyping Using the <SCRIPT> Tag <script src= url ></script> SRC property is required only if you place your program in a separate file <script> script commands and comments </script> Older versions of HTML (before 5) used a slightly different format <script type= text/javascript > This is no longer necessary, simply use <script> Extensible Networking Platform 8 8 - CSE 330 Creative Programming and Rapid Prototyping

JavaScript Example (part 1) <!DOCTYPE html> <html> <head><title>my JavaScript Example</title> <script> function MsgBox(textstring) { alert(textstring); } </script> Extensible Networking Platform 9 9 - CSE 330 Creative Programming and Rapid Prototyping JavaScript Example (part 2) <body> <form> <INPUT NAME="text1" TYPE=Text> <INPUT NAME="submit" TYPE=Button VALUE="Show Me" onclick="msgbox(form.text1.value) > </form> </body> </html> Extensible Networking Platform 10 10 - CSE 330 Creative Programming and Rapid Prototyping

JavaScript Example <!DOCTYPE html> <html> <head><title>my JavaScript Example</title> <script> function MsgBox(textstring) { alert(textstring); } </script> </head> <body> <form> <INPUT NAME="text1" TYPE=Text> <INPUT NAME="submit" TYPE=Button VALUE="Show Me" onclick="msgbox(form.text1.value) > </form> </body> </html> Extensible Networking Platform 11 11 - CSE 330 Creative Programming and Rapid Prototyping JavaScript Event Listeners We can control events in a more granular way using Event Listeners Event Listeners allow for custom behavior for every element document.getelementbyid("hello").addeventlistener("click",msgbox, false); Extensible Networking Platform 12 12 - CSE 330 Creative Programming and Rapid Prototyping

JavaScript Additional Information The CSE 330 Wiki provides a great intro into JavaScript along with some excellent links to more comprehensive tutorials Additional JS tutorials http://www.quirksmode.org/js/contents.html https://docs.webplatform.org/wiki/meta:javascript/t utorials Extensible Networking Platform 13 13 - CSE 330 Creative Programming and Rapid Prototyping JavaScript Debugging JSHint is a great resources to help debug your code http://www.jshint.com/ Tools for browsers also exist Firefox Firebug extension Chrome and Safari WebkitInspector comes bundled with the browser Extensible Networking Platform 14 14 - CSE 330 Creative Programming and Rapid Prototyping

JavaScript Examples http://research.engineering.wustl.edu/~todd/cse330/demo/lecture5/ Extensible Networking Platform 15 15 - CSE 330 Creative Programming and Rapid Prototyping AJAX Stands for Asynchronous JavaScript and XML Development technique for creating interactive web applications Not a new Technology but more of a Pattern Extensible Networking Platform 16 16 - CSE 330 Creative Programming and Rapid Prototyping

Motivation for AJAX Web pages always RELOAD and never get UPDATED Users wait for the entire page to load even if a single piece of data is needed Single request/response restrictions Extensible Networking Platform 17 17 - CSE 330 Creative Programming and Rapid Prototyping Components HTML (or XHTML) and CSS Presenting information Document Object Model Dynamic display and interaction with the information XMLHttpRequest object Retrieving data ASYNCHRONOUSLY from the web server. Javascript Binding everything together Extensible Networking Platform 18 18 - CSE 330 Creative Programming and Rapid Prototyping

The DOM Document Object Model (DOM): platform- and language-independent way to represent XML Adopts a tree-based representation W3C standard, supported by modern browsers JavaScript uses DOM to manipulate content To process user events To process server responses (via XMLHttpRequest) Extensible Networking Platform 19 19 - CSE 330 Creative Programming and Rapid Prototyping The DOM Unlike other programming languages, JavaScript understands HTML and can directly access it JavaScript uses the HTML Document Object Model to manipulate HTML The DOM is a hierarchy of HTML things Use the DOM to build an address to refer to HTML elements in a web page Levels of the DOM are dot-separated in the syntax Extensible Networking Platform 20 20 - CSE 330 Creative Programming and Rapid Prototyping

DOM Extensible Networking Platform 21 21 - CSE 330 Creative Programming and Rapid Prototyping Accessing the DOM Example https://research.engineering.wustl.edu/~todd/cse330/demo/lecture5/ Extensible Networking Platform 22 22 - CSE 330 Creative Programming and Rapid Prototyping

Web Application and AJAX Extensible Networking Platform 23 23 - CSE 330 Creative Programming and Rapid Prototyping Request Processing Extensible Networking Platform 24 24 - CSE 330 Creative Programming and Rapid Prototyping

Asynchronous processing - XMLHttpRequest Allows to execute an HTTP request in background Callbacks kick back into Javascript Code Supported in all standard browsers Extensible Networking Platform 25 25 - CSE 330 Creative Programming and Rapid Prototyping Using XMLHttpRequest First you must create the XMLHttpRequest Object in JavaScript Example var xmlhttp = new XMLHttpRequest(); Older browsers might require different syntax For example (Internet Explorer versions <9) var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); We will not worry about JS compatibility with IE < 9 in this course Extensible Networking Platform 26 26 - CSE 330 Creative Programming and Rapid Prototyping

Using XMLHttpRequest Transferring data to Server Open() to initialize connection to Server Send() to send the actual Data Example (POST) xmlhttp.open("post", "/query.cgi,true); xmlhttp.send("name=bob&email=bob@example.com"); Example (GET) xmlhttp.open("get","hello.txt",true); xmlhttp.send(null); Extensible Networking Platform 27 27 - CSE 330 Creative Programming and Rapid Prototyping What happens after sending data? XMLHttpRequest contacts the server and retrieves the data Can take indeterminate amount of time Create an Event Listener to determine when the object has finished loading with the data we are interested in Specifically listen for the load event to occur Extensible Networking Platform 28 28 - CSE 330 Creative Programming and Rapid Prototyping

Events of interest xmlhttp.addeventlistener("load,mycallbackfunction,false); Extensible Networking Platform 29 29 - CSE 330 Creative Programming and Rapid Prototyping Using XMLHttpRequest Parse and display data responsexml DOM-structured object responsetext One complete string Examples var namenode = requester.responsexml.getelementsbytagname("name")[0]; var nametextnode = namenode.childnodes[0]; From an event function mycallback(event) { alert( The response + event.target.responsetext); } Extensible Networking Platform 30 30 - CSE 330 Creative Programming and Rapid Prototyping

AJAX Example <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.open("get","hello.txt",true); xmlhttp.addeventlistener("load,mycallback,false); xmlhttp.send(null); function mycallback(event) { alert( The response + event.target.responsetext); } </script> Extensible Networking Platform 31 31 - CSE 330 Creative Programming and Rapid Prototyping Interaction between Components Extensible Networking Platform 32 32 - CSE 330 Creative Programming and Rapid Prototyping

AJAX Example Extensible Networking Platform 33 33 - CSE 330 Creative Programming and Rapid Prototyping jquery Simplify your JavaScript Extensible Networking Platform 34 34 - CSE 330 Creative Programming and Rapid Prototyping

What is jquery? A framework for Client Side JavaScript Frameworks provide useful alternatives for common programming tasks, creating functionality which may not be available or cumbersome to use within a language. An open source project, maintained by a group of developers, with a very active support base and thorough, well written documentation. Extensible Networking Platform 35 35 - CSE 330 Creative Programming and Rapid Prototyping What jquery is not A substitute for knowing JavaScript jquery is extraordinarily useful, but you should still know how JavaScript works and how to use it correctly. This means more than Googling a tutorial and calling yourself an expert. A solve all There is still plenty of functionality built into JavaScript that should be utilized! Don t turn every project into a quest to jquery-ize the problem, use jquery where it makes sense. Create solutions in environments where they belong. Extensible Networking Platform 36 36 - CSE 330 Creative Programming and Rapid Prototyping

What is available with jquery? Cross browser support and detection AJAX functions CSS functions DOM manipulation DOM transversal Attribute manipulation Event detection and handling JavaScript animation Hundreds of plugins for pre-built user interfaces, advanced animations, form validation, etc Expandable functionality using custom plugins Small foot print Extensible Networking Platform 37 37 - CSE 330 Creative Programming and Rapid Prototyping The jquery/$ Object Represented by both $ and jquery To use jquery only, use jquery.noconflict(), for other frameworks that use $ By default,$ represents the jquery object. When combined with a selector, can represent multiple DOM Elements Used with all jquery functions. Extensible Networking Platform 38 38 - CSE 330 Creative Programming and Rapid Prototyping

jquery basic syntax $(selector).action() jquery Examples $ sign used to access jquery Selector finds the HTML element(s) An action is performed on the element(s) Examples $(this).hide() //hides current element $( p ).hide() //hides all <p> elements $(.test ).hide() //hides all elements with class= test $( #test ).hide() //hides the element with id= test Extensible Networking Platform 39 39 - CSE 330 Creative Programming and Rapid Prototyping jquery & AJAX jquery has a series of functions which provide a common interface for AJAX, no matter what browser you are using Most of the upper level AJAX functions have a common layout: $.func(url[,params][,callback]), [ ] optional url: string representing server target params: names and values to send to server callback: function executed on successful communication. Extensible Networking Platform 40 40 - CSE 330 Creative Programming and Rapid Prototyping

jquery AJAX Functions $.func(url[,params][,callback]) $.get $.getjson $.getifmodified $.getscript $.post $(selector), inject HTML load loadifmodified $(selector), ajaxsetup alts ajaxcomplete ajaxerror ajaxsend ajaxstart ajaxstop ajaxsuccess $.ajax, $.ajaxsetup async beforesend complete contenttype data datatype error global ifmodified processdata success timeout type url Extensible Networking Platform 41 41 - CSE 330 Creative Programming and Rapid Prototyping Example Show/Hide the old way <a href="#" onclick="toggle_visibility('foo');">click here to toggle visibility of #foo</a> function toggle_visibility(id) { var e = document.getelementbyid(id); if(e.style.display == 'block') e.style.display = 'none'; else e.style.display = 'block'; } Extensible Networking Platform 42 42 - CSE 330 Creative Programming and Rapid Prototyping

Example Show/Hide with jquery $().ready(function(){ $("a").click(function(){ $("#more").toggle("slow"); return false; }); }); Extensible Networking Platform 43 43 - CSE 330 Creative Programming and Rapid Prototyping Example Ajax the old way function GetXmlHttpObject(handler) { var objxmlhttp = null; //Holds the local xmlhttp object instance } //Depending on the browser, try to create the xmlhttp object if (is_ie){ var strobjname = (is_ie5)? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP'; try{ objxmlhttp = new ActiveXObject(strObjName); objxmlhttp.onreadystatechange = handler; } catch(e){ //Object creation errored alert('verify that activescripting and activex controls are enabled'); return; } } else{ // Mozilla Netscape Safari objxmlhttp = new XMLHttpRequest(); objxmlhttp.onload = handler; objxmlhttp.onerror = handler; } //Return the instantiated object return objxmlhttp; Extensible Networking Platform 44 44 - CSE 330 Creative Programming and Rapid Prototyping

Example Ajax with jquery $.get("update_actions.aspx", {st: "yes", f: $(this).attr("id")} ); Extensible Networking Platform 45 45 - CSE 330 Creative Programming and Rapid Prototyping jquery Examples Extensible Networking Platform 46 46 - CSE 330 Creative Programming and Rapid Prototyping

Calendar Examples Extensible Networking Platform 47 47 - CSE 330 Creative Programming and Rapid Prototyping