Using jQuery / APIs / JSON Dr. Charles Severance www.php-intro.com.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

23-Aug-14 HTML/XHTML Forms. 2 What are forms? is just another kind of XHTML/HTML tag Forms are used to create (rather primitive) GUIs on Web pages Usually.
JavaScript and AJAX Jonathan Foss University of Warwick
JQuery CS 380: Web Programming. What is jQuery? jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling,
JavaScript Functions, Objects, Array, and Control Structures Dr. Charles Severance
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
The Browser Object Model (BOM) The API of JavaScript’s browser host environment SE-2840 Dr. Mark L. Hornick 1.
JQuery. What is jQuery? jQuery is a fast, small, and feature-rich JavaScript library that simplifies HTML document traversing and manipulation event handling.
Philly.NET Hands-On jQuery + Plug-ins Bill Wolff, Rob Keiser.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
Cookies, Sessions, and Authentication Dr. Charles Severance
JQuery CS 268. What is jQuery? From their web site:
Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000.
CGI and AJAX CS-260 Dick Steflik.
JavaScript & jQuery the missing manual Chapter 11
Programming Games Review for midterm. Work session. Homework: Prepare for midterm.
JQuery 10/21. Today jQuery Some cool tools around the web JavaScript Libraries Drawing libraries HTML Frameworks Conventions.
JavaScript Lecture 6 Rachel A Ober
UFCEWT-20-3 Advanced Topics in Web Development Lecture 4 : JavaScript, Browsers & the HTML DOM-API.
RESTful applications Norman White. REST Representational state transfer Key concepts – Client Server architecture built on transferring resources between.
Modern JavaScript Develop And Design Instructor’s Notes Chapter 13 - Frameworks Modern JavaScript Design And Develop Copyright © 2012 by Larry Ullman.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Javascript Intro
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
HTML Form Widgets. Review: HTML Forms HTML forms are used to create web pages that accept user input Forms allow the user to communicate information back.
Web Design: Basic to Advanced Techniques Fall 2010 Mondays 7-9pm 200 Sutardja-Dai Hall Introduction to PHP.
Computer Science and Software Engineering© 2014 Project Lead The Way, Inc. HTML5 Evolving Standards JavaScript.
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.
06 – Java Script (2) Informatics Department Parahyangan Catholic University.
JQuery and AJAX WEB Technologies : PHP Programming Language.
JavaScript Dr. Charles Severance
AJAX. Ajax  $.get  $.post  $.getJSON  $.ajax  json and xml  Looping over data results, success and error callbacks.
Javascript Overview. What is Javascript? May be one of the most popular programming languages ever Runs in the browser, not on the server All modern browsers.
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.
Forms and PHP Dr. Charles Severance
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Overview Web Technologies Computing Science Thompson Rivers University.
Using jQuery Dr. Charles Severance
Using Handlebars Dr. Charles Severance
David Tarrant Electronics and Computer Science.
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
How to consume a RESTful service using jQuery. Introduction  In this post we see how to consume the RESTful service described in the post Design a RESTful.
JQuery, JSON, AJAX. AJAX: Async JavaScript & XML In traditional Web coding, to get information from a database or a file on the server –make an HTML form.
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
CSCI 3100 Tutorial 5 JavaScript & Ajax Jichuan Zeng Department of Computer Science and Engineering The Chinese University of Hong.
Introduction to Dynamic Web Content Dr. Charles Severance
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Dr. Charles Severance Using Handlebars Dr. Charles Severance
Our Technologies Dr. Charles Severance
Web Technologies Computing Science Thompson Rivers University
JavaScript Dr. Charles Severance
Tek Raj Chhetri Code for Humans not for machine.
Using JSON Dr. Charles Severance
AJAX and REST.
JQUERY Online TRAINING AT GOLOGICA
Web Browser server client 3-Tier Architecture Apache web server PHP
Using jQuery Dr. Charles Severance
..
MIS JavaScript and API Workshop (Part 3)
Web Technologies Computing Science Thompson Rivers University
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Front End Development workshop
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Murach's JavaScript and jQuery (3rd Ed.)
Presentation transcript:

Using jQuery / APIs / JSON Dr. Charles Severance

Web ServerDatabase Server Time Apache PHP MySql Browser JavaScript DOMDOM PDOPDO Parse HTML

Document Object Model JavaScript can manipulate the current HTML docment The “Document Object Model” tells us the syntax to use to access various “bits” of the current screen to read and/or manipulate You can even find pieces of the model by id attribute and change them We can read and write the DOM from JavaScript del

DOM's are not Identical Not all browsers represent their page exactly the same. This makes it a challenge to keep all of your JavaScript working on all browsers Also means you need to test your code over and over on each browser Aargh..

jQuery to the rescue While the DOM's are not particularly portable, and direct DOM manipulation is a little clunky, there are a number of JavaScript frameworks that handle the myriad of subtle differeces between browsers With jQuery, instead of manipulating the DOM, we use jQuery functions and everything works much better...

John Resig Started jQuery in 2005 to make his web development projects easier Elegant way to select DOM elements Clean way to register events Released in 2006 Works at Khan Academy as the "Dean of Computer Science"

jQuery Documentation The web is a wonderful source of jQuery documentation

jquery- 01/hello.php Here is some awesome page content $(document).ready(function(){ alert("Hello jQuery World!"); window.console && console.log('Hello jQuery..'); });

ze/ jquery- 01/resize.php $(window).resize(function() { console.log('.resize() called. width='+ $(window).width()+' height='+$(window).height()); }); Here is some awesome page content

jquery-01/toggle.php Where is the spinner? <img id="spinner" src="spinner.gif" height="25" style="vertical-align: middle; display:none;"> <a href="#" onclick="$('#spinner').toggle(); return false;">Toggle <a href="#" onclick="$('#para').css('background-color', 'red'); return false;">Red <a href="#" onclick="$('#para').css('background-color', 'green'); return false;">Green

jquery-01/autopost.php <input type="text" name="one" value="Hello there" style="vertical-align: middle;"/> <img id="spinner" src="spinner.gif" height="25" style="vertical-align: middle; display:none;">... <?php sleep(5); echo('You sent: '.$_POST['val']); jquery-01/autoecho.php

jquery-01/autopost.php $('#target').change(function(event) { $('#spinner').show(); var form = $('#target'); var txt = form.find('input[name="one"]').val(); window.console && console.log('Sending POST'); $.post( 'autoecho.php', { 'val': txt }, function( data ) { window.console && console.log(data); $('#result').empty().append(data); $('#spinner').hide(); } ).error( function() { window.console && console.log('error'); });

JavaScript Object Notation

Douglas Crockford - "Discovered" JSON Object literal notation in JavaScript

Associative Arrays Objects JavaScript Associative Arrays are actually objects with member variables They can be accessed with either associative array syntax or object syntax

balls = {"golf": "Golf balls", "tennis": "Tennis balls", "ping": "Ping Pong balls"}; balls.soccer = "Soccer balls"; balls['lacross'] = "Lacross balls"; console.dir(balls);

who = { 'name': 'Chuck', 'age': 29, 'college': true, 'offices' : [ '3350DMC', '3437NQ' ], 'skills' : { 'fortran': 10, 'C': 10, 'C++': 5, 'python' : '7' } }; Strin g Intege r Boolea n List/Arra y Objec t JSON Syntax

who = { 'name': 'Chuck', 'age': 29, 'college': true, 'offices' : [ '3350DMC', '3437NQ' ], 'skills' : { 'fortran': 10, 'C': 10, 'C++': 5, 'python' : '7' } }; window.console && console.log(who); Check out the console.log to see the cool object.... json-01/syntax.php Constant

... $(document).ready( function () { $.getJSON('json.php', function(data) { $("#back").html(data.first); window.console && console.log(data); }) } );... json-01/index.php json-01/json.php <?php sleep(2); header('Content-Type: application/json; charset=utf-8'); $stuff = array('first' => 'first thing', 'second' => 'second thing'); echo(json_encode($stuff));

json-02-chat/index.php <?php session_start(); if ( isset($_POST['reset']) ) { $_SESSION['chats'] = Array(); header("Location: index.php"); return; } if ( isset($_POST['message']) ) { if ( !isset ($_SESSION['chats']) ) $_SESSION['chats'] = Array(); $_SESSION['chats'] [] = array($_POST['message'], date(DATE_RFC2822)); header("Location: index.php"); return; } ?>

json-02-chat/index.php Chat....

function updateMsg() { window.console && console.log("Requesting JSON"); $.ajax({ url: "chatlist.php", cache: false, success: function(data){ window.console && console.log("JSON Received"); window.console && console.log(data); $("#chatcontent").empty(); for (var i = 0; i < data.length; i++) { entry = data[i]; $("#chatcontent").append(" "+entry[0] + " "+entry[1]+" \n"); } setTimeout('updateMsg()', 4000); } }); } window.console && console.log("Startup complete"); updateMsg(); // Call the first time to get things started json-02-chat/index.php

<?php session_start(); sleep(5); header('Content-Type: application/json; charset=utf-8'); if ( !isset($_SESSION['chats']) ) $_SESSION['chats'] = array(); echo(json_encode($_SESSION['chats'])); json-02-chat/chatlist.php

json-03-crud