CGI and AJAX CS-260 Dick Steflik.

Slides:



Advertisements
Similar presentations
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
Advertisements

6/3/2015eBiquity1 Tutorial on AJAX Anubhav Kale (akale1 AT cs DOT umbc DOT edu)
Asynchronous HTTP request generation in JavaScript (AJAX)
Cloud Computing Lecture #7 Introduction to Ajax Jimmy Lin The iSchool University of Maryland Wednesday, October 15, 2008 This work is licensed under a.
1 JavaScript & AJAX CS , Spring JavaScript.
More APIs: Web Services CMPT 281. Announcements Project milestone Lab: – Web services examples.
Web Development & Design Foundations with XHTML Chapter 9 Key Concepts.
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.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
INT222 – Internet Fundamentals Weekly Notes: AJAX and Canvas 1.
Introduction to AJAX AJAX Keywords: JavaScript and XML
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
Ajax Basics The XMLHttpRequest Object. Ajax is…. Ajax is not…. Ajax is not a programming language. Ajax is not a programming language. Ajax is a methodology.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
AJAX and Java ISYS 350. AJAX Asynchronous JavaScript and XML: – Related technologies: JavaScript, Document Object Model, XML, server-side script such.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Intro to Ajax Fred Stluka Jan 25, /25/2006Intro to AjaxFred Stluka2 What is Ajax? "Asynchronous JavaScript and XML" New name for an old technique:
Lecture 13 – XML and JSON SFDV3011 – Advanced Web Development Reference: 1.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
HTML5. HTML5’s overall theme The browser as a rich application platform rich, cross-device user interfaces offline operation capability hardware access.
Ajax In Action The Journey into Web2.0 Presented by Eric Pascarello.
AJAX (also known as: XMLHTTP, Remote Scripting, XMLHttpRequest, etc.) Matt Warden.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
Scripting Languages Client Side and Server Side. Examples of client side/server side Examples of client-side side include: JavaScript Jquery (uses a JavaScript.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
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.
JavaScript & Introduction to AJAX
What is AJAX ? Asynchronous Javascript and XML. Not a stand-alone language or technology. It is a technique that combines a set of known technologies in.
AJAX – Asynchronous JavaScript And XML By Kranthi Kiran Nuthi CIS 764 Kansas State University.
Internet Technologies #6 REST SOAP AJAX. Agenda  REST  SOAP  AJAX.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
 AJAX technology  Rich User Experience  Characteristics  Real live examples  JavaScript and AJAX  Web application workflow model – synchronous vs.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
1 AJAX. AJAX – Whatzit? Asynchronous (content loading)‏ Javascript (logic & control)‏ And XML (request handling)‏
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
A New Way To Web Applications Development Tin Htut Htut Naing Oo Myanmar Information Technology.
JavaScript and Ajax Week 10 Web site:
CITA 330 Section 10 Web Remoting Techniques. Web Remoting Web Remoting is a term used to categorize the technique of using JavaScript to directly make.
NCCUCS 軟體工程概論 Lecture 5: Ajax, Mashups April 29, 2014.
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.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Open Solutions for a Changing World™ Eddy Kleinjan Copyright 2005, Data Access WordwideNew Techniques for Building Web Applications June 6-9, 2005 Key.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
What is AJAX ? Asynchronous Javascript and XML.
JavaScript and Ajax (Ajax Tutorial)
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
AJAX and REST.
XMLHttp Object.
AJAX.
CSE 154 Lecture 22: AJAX.
JavaScript & AJAX.
JavaScript & jQuery AJAX.
Chengyu Sun California State University, Los Angeles
AJAX CS-422 Dick Steflik.
Intro to Ajax Fred Stluka Jan 25, 2006.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
Ajax and JSON Jeremy Shafer Department of MIS Fox School of Business
Presentation transcript:

CGI and AJAX CS-260 Dick Steflik

CGI Common Gateway Interface A set of standards that define how information is exchanged between a web server and a ccustom script CGI Spec is maintained by NCSA (National Center for Supercomputing Applications A standard for external gateway programs to interface with information servers such as HTTP servers

When running a python program as a CGI program sysin , sysout and syserr are redefined to : sysin: instead of coming from the keyboard is the incoming data stream from the tcpip socket (the remote host, the user’s browser). This will actually be handled via CGI Environment variables sysout: instead of printing to the screen prints to the tcpip outgoing data stream, to the user’s browser)

Input Input for your CGI program will be handled by the HTTP server (Apache) and will be placed in a set of HTTP environment variables, and in a special data structure called FieldStorage.

FieldStorage Methods: add_field(name,value clear() get(name, default) getfirst(name[,default]) getlist(name) has_key(name) Items() keys()

What is AJAX Asynchronous Javascript And XML allows the updating of a web page without doing a page reload creates much nicer user experience AJAX is not really a technology by itself combination of Javascript, XML and some server-side scripting to create the XML server-side scripting could be done in PHP, .NET, Java Servlet or Java Server Page (JSP)

General Technique Server-side Script Web Page requests server-side script to be run script run, XML created info parsed from XML and used to update DOM by Javascript XML document returned

Sending a request for a URL xmlHttpRequest Object mozilla objXMLHttp=new XMLHttpRequest() IE objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP") create the URL tell the browser the name of the function to handle the response send the url to the server

example var url="servertime.php" xmlHttp.onreadystatechange=stateChanged xmlHttp.open("GET",url,true) xmlHttp.send(null)

The server-side script creates a “well formed XML document” sets the content type to text/xml can be written in any language Python PHP ASP .NET Java JSP

sample PHP script <? // a time document header("Content-type: text/xml"); print("<time>"); print("<currtime>".time()."</currtime>"); print("</time>"); ?>

stateChange when the document is received by the browser control is transferred to where ever we told it to xmlHttp.onreadystatechange=stateChanged in this case the function named stateChanged

stateChanged function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") //update the DOM with the data document.getElementById("time").innerHTML=xmlHttp.responseText }

XMLHttpRequest Object Methods: abort() - stop the current request getAllResponseHeaders - Returns complete set of headers (labels and values) as a string getResponseHeader(:headerLabel”) – returns the string value of the requested header field open(“method”,”URL”) sets a pending request send(content) – transmits the request setRequestHeader(“label”,”value”) – sets label/value in the header

(continued) Properties onreadystatechange - event handler to use readyState (0-uninitialized, 1-loading, 2-loaded, 3-interactive, 4- complete) responseText – string version of the data returned responseXML – DOM compatible document object returned by server status – http response header code (200 – good) statusText – string message of status code

Popular Ajax Frameworks Prototype http://www.prototypejs.org/ free Script.aculo.us http://script.aculo.us/ Used with the Prototype Framework, mainly for animations and interface development Backbase Enterprise Ajax Framework not free

JSON JavaScript Object Notation Text based open standard for human readable data interchange Often used in AJAX interchange techniques RFC-4627 ( http://www.ietf.org/rfc/rfc4627.txt ) An alternative to using XML for AJAX

Sample JSON Object { "firstName": "John", "lastName": "Smith", "age": 25, "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": 10021 }, "phoneNumbers": [ "type": "home", "number": "212 555-1234“ }, "type": "fax", "number": "646 555-4567“ } ]

var my_JSON_object = {}; var http_request = new XMLHttpRequest(); http_request.open("GET", url, true); http_request.onreadystatechange = function () { var done = 4, ok = 200; if (http_request.readyState == done && http_request.status == ok) { my_JSON_object = JSON.parse(http_request.responseText); } }; http_request.send(null);

My_JSON_object.firstname=“John”; My_JSON_object.lastname=“Smith”; My_JSON_object.age=25; My_JSON_object.address.streetaddress=“21 2nd Street”; My_JSON_object.address.city=“New York”; .

jQuery Multi-browser javascript library to simplify client-side scripting. Used by over 55% of the top 10000 most visited web sites Goal is to make it easier to navigate html documents, select DOM elements, create animations, handle events and develop AJAX applications.

jQuery Features: DOM element selection DOM traversal and modification (including CSS) DOM manipulation based on CSS selectors Events AJAX Extensibility via plug-ins Utilities (user-agent info and feature detection) Compatibility methods for compatibility with older browsers Multi-browser (not cross browser) support To use you must include jquery.js (available from jquery.com) via the src attribute of the html <script) tag

Feature Detection // check if jQuery is included, if not then include it if(!(window.jQuery && window.jQuery.fn.jquery == '1.6.2')) { var s = document.createElement('script'); s.setAttribute('src', ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js'); s.setAttribute('type', 'text/javascript'); document.getElementsByTagName('head')[0].appendChild(s); }

jQuery/AJAX $.ajax({ type: "POST", url: "example.php", data: "name=John&location=Boston“ }).done( function(msg) { alert( "Data Saved: " + msg ); }).fail( function( xmlHttpRequest, statusText, errorThrown ) { alert( "Your form submission failed.\n\n" + "XML Http Request: " + JSON.stringify( xmlHttpRequest ) + ",\nStatus Text: " + statusText + ",\nError Thrown: " + errorThrown ); });