Step Outside the Box – Part II ColdFusion and Ajax.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Introducing JavaScript
JavaScript and AJAX Jonathan Foss University of Warwick
Java Script Session1 INTRODUCTION.
1 CSC 551: Web Programming Spring 2004 client-side programming with JavaScript  scripts vs. programs  JavaScript vs. JScript vs. VBScript  common tasks.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
Step Outside the Box – Part I. Theo Rushin Jr I am an avid snowboarder and skier always looking for the deep powder. When I’m not carving my way through.
Server-Side vs. Client-Side Scripting Languages
1 Chapter 12 Working With Access 2000 on the Internet.
Tutorial 10 Programming with JavaScript
1 JavaScript & AJAX CS , Spring JavaScript.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Chapter 6 DOJO TOOLKITS. Objectives Discuss XML DOM Discuss JSON Discuss Ajax Response in XML, HTML, JSON, and Other Data Type.
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.
CST JavaScript Validating Form Data with JavaScript.
Prof. James A. Landay University of Washington Spring 2008 Web Interface Design, Prototyping, and Implementation Rich Internet Applications: AJAX, Server.
M. Taimoor Khan * Java Server Pages (JSP) is a server-side programming technology that enables the creation of dynamic,
4.1 JavaScript Introduction
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
JavaScript & jQuery the missing manual Chapter 11
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
AJAX By Steven Hernandez Research Analyst NIATEC.
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
CITS1231 Web Technologies JavaScript and Document Object Model.
Copyright 2007 Adobe Systems Incorporated. 1 ColdFusion 8 : Advanced AJAX Development Rakshith N Computer Scientist Jan 02, 2008.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Javascript. Outline Introduction Fundamental of JavaScript Javascript events management DOM and Dynamic HTML (DHTML)
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
JavaScript. Overview Introduction: JavaScript basics Expressions and types Expressions and types Arrays Arrays Objects and Associative Arrays Objects.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
Tutorial 10 Programming with JavaScript. XP Objectives Learn the history of JavaScript Create a script element Understand basic JavaScript syntax Write.
Tutorial 10 Programming with JavaScript
Using Client-Side Scripts to Enhance Web Applications 1.
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Random Logic l Forum.NET l AJAX Behind the buzz word Forum.NET ● January 23, 2006.
Virtual Earth Map Control V4 MARK MAGLIOCCO Phillydotnet.org 11/21/2006
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Web Technology Introduction AJAXAJAX. AJAX Outline  What is AJAX?  Benefits  Real world examples  How it works  Code review  Samples.
SYST Web Technologies SYST Web Technologies AJAX.
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
AJAX Asynchronous JavaScript and XML 1. AJAX Outline What is AJAX? Benefits Real world examples How it works 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
 Web pages originally static  Page is delivered exactly as stored on server  Same information displayed for all users, from all contexts  Dynamic.
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.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
CHAPTER 8 AJAX & JSON WHAT IS AJAX? Ajax lets you…
AJAX Use Cases for WSRP Subbu Allamaraju BEA Systems Inc WSRP F2F Meeting, May 2006.
Tutorial 10 Programming with JavaScript. 2New Perspectives on HTML, XHTML, and XML, Comprehensive, 3rd Edition Objectives Learn the history of JavaScript.
 AJAX technology  Rich User Experience  Characteristics  Real live examples  JavaScript and AJAX  Web application workflow model – synchronous vs.
Introduction to AJAX MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/4/2016.
JQUERY AND AJAX
JavaScript and AJAX 2nd Edition Tutorial 1 Programming with JavaScript.
XP Tutorial 10New Perspectives on HTML, XHTML, and DHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties.
JQuery form submission CIS 136 Building Mobile Apps 1.
AJAX. Objectives Understand and apply AJAX Using AJAX in DOJO library.
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 JavaScript
JavaScript and Ajax (Ajax Tutorial)
CSE 154 Lecture 11: AJAx.
Not a Language but a series of techniques
Tutorial 10 Programming with JavaScript
CSE 154 Lecture 11: AJAx.
CSE 154 Lecture 22: AJAX.
AJAX Robin Burke ECT 360.
Presentation transcript:

Step Outside the Box – Part II ColdFusion and Ajax

Theo Rushin Jr I am an avid snowboarder in the winter and paintball player during the other seasons. During the week I work as an independent consultant for hire. I have spent the past 6+ years establishing myself as an expert Coldfusion and Flash Rich Internet Application Developer and Trainer. During my 6 years of web application development I have created and supported many enterprise-wide web-based applications I have worked on various development efforts using technologies such as ColdFusion, Flash Actionscript, and Ajax. I can be reached at or on the

ColdFusion and Ajax What Is AJAX? Asynchronous JavaScript and XML AJAX itself is not a technology but a collection of existing technologies used in such a way to provide a more responsive, interactive, and Rich Internet Application-like experience. The key technology used in AJAX is the XMLHttpRequest object. It provides the capability to transmit data to and from the server without refreshing the entire page. The page then communicates with the browser’s Document Object Model (DOM) to update the page.

ColdFusion and Ajax What Is AJAX? (continued) Here are the basic technologies involved in Ajax applications: HTML is used to build Web forms and identify fields for use in the rest of your application. JavaScript code is the core code running Ajax applications and it helps facilitate communication with server applications using the XMLHTTPRequest object. DHTML, or Dynamic HTML, helps you update your forms dynamically. You'll use div, span, and other dynamic HTML elements to mark up your HTML. DOM, the Document Object Model, will be used (through JavaScript code) to work with both the structure of your HTML and (in some cases) XML returned from the server.

ColdFusion and Ajax Is Ajax a Web 2.0 technology? Well … Yes and No

ColdFusion and Ajax Is Ajax a Web 2.0 technology? No because … Ajax is nothing new and has been around for years. The XMLHttpRequest object was introduced in the Internet Explorer browser back in Companies such as Google, Netflix, and Yahoo have recently re-ignited the interest in using these technologies. Take a look at these sites:

ColdFusion and Ajax Is Ajax a Web 2.0 technology? Yes because … The technologies that makeup Ajax play an integral part in delivering sites that are very interactive, responsive, and deliver a Rich Internet Application-like experience. Check out these sites:

ColdFusion and Ajax Q:What are Mashups? A: A mashup is a website or web application that seamlessly combines content from more than one source into an integrated experience. Content used in mashups is typically sourced from a third party via a public interface or API. Other methods of sourcing content for mashups include Web feeds (e.g. RSS or Atom) and JavaScript. Excerpt from:

ColdFusion and Ajax Q:How can I integrate AJAX into my ColdFusion apps? A:Use CFAJAX. CFAjax is an AJAX implementation for ColdFusion applications. It allows your ColdFusion pages to communicate with ColdFusion methods using JavaScript. CFAjax comes with easy to use JavaScript and ColdFusion API methods that help marshal the response between your CF methods and client page. CFAjax is an open source product, you are free to use and distribute CFAjax with your applications. The home for this tools is:

ColdFusion and Ajax Q:What browsers support CFAJAX? A: CFAJAX works on the following browsers: CFAJAX currently works on the following browsers: Firefox 1.0+ I.E Mozilla 1.0+ Netscape 7.0+ Safari 1.2+

ColdFusion and Ajax Q:So, how do I use CFAJAX? A: After you have downloaded, installed, and configured the tool you may begin to use the following methods to make AJAX calls.

ColdFusion and Ajax function getStateInfo() { var stateName = DWRUtil.getValue("state"); DWREngine._execute(_cfscriptLocation, null, ‘getStateInfo', stateName, getStateInfo_result); } JavaScript function called when user clicks on an element on the page. getStateInfo() – Javascript function that is called on the onClick event. DWRUtil.getValue – CFAJAX method that returns the selected value in a form element. DWREngine._execute – CFAJAX method that calls the server-side function passing the state variable. o_cfscriptLocation: A pointer to the location of the server-side ColdFusion template page. onull: Default value ogetStateInfo: CF function that will be executed ostateName: Parameter being passed to CF function ogetStateInfo_result: JavaScript callback function resortViewer.cfm

ColdFusion and Ajax function getStateInfo_result(result) { var divText = “”; for(i = 0; I < result.length; i++) { divText = divText + result[i].resortName + “ ”; } document.getElementById(“resortListing").innerHTML = divText; } JavaScript callback function called after the server-side function returns its results. You use this function to process the data that was returned from the CF function. resortViewer.cfm

ColdFusion and Ajax SELECT * FROM Resort WHERE state = ‘#stateName#’ ColdFusion function used to retrieve all records containing the passed in stateName. resorts.cfm

ColdFusion and Ajax Q:What other data types can I return? A: CFAJAX will allow you to return a variety of data types including; Strings Numerics Booleans Arrays Structures CFCs

ColdFusion and Ajax CF JS alert(result + “ THEO”) String The return for a ColdFusion string is a JavaScript string.

ColdFusion and Ajax CF JS var myAge = +return ; Numeric Numerics returned from ColdFusion become JavaScript strings. If you return a numeric and then use the + operator in JavaScript to try to add something to it, JavaScript will join the two. You must first convert the returned value in JavaScript to a number first (e.g. var myCalc = +return + 23;)

ColdFusion and Ajax CF JS if(return == “YES”) { alert(“Yes it is true”) } else { alert(“Completely false”) } Boolean Booleans are returned as a “YES” or “NO” (all CAPS) for true or false. You may then need to convert to JavaScript booleans.

ColdFusion and Ajax CF JS for(i=0; i < result.length; i++) { alert(result[i]) } Array Only single dimension arrays are supported by CFAJAX. While ColdFusion arrays start at index 1, JavaScript arrays start at index 0.

ColdFusion and Ajax CF JS theStructNumberKey = return[0].KEY // returns "MYNUMBER" theStructNumberValue = return[0].VALUE // returns "1" theStructStringKey = return[1].KEY // returns "MYSTRING" theStructStringValue = return[1].VALUE // returns "hello" Structure A CF struct comes back as an array of objects. Each object has two properties, KEY and VALUE (note the CAPS; the key itself is also in CAPS as in the example), representing the key and value of a member in the CF struct; the array contains each of those members e.g.:

ColdFusion and Ajax CF SELECT * FROM Resort WHERE state = ‘#stateName#’ JS myFirstRowID = result[0].ID; mySecondRowDate = result[1].DATE; etc. Query The JS object that represents a CF query is an array of row objects, with each column as a property of each object. E.G. a cfquery that returns columns ID, NAME, DATE, SIZE and has 10 rows would become a JS array of length 10, with each element an object with properties ID, NAME, DATE, SIZE (note the CAPS - all column names are capitalized in the JS object):

ColdFusion and Ajax CF JS theCFCMyNumberKey = return[0].KEY // returns "MYNUMBER" theCFCMyNumberValue = return[0].VALUE // returns "1" theCFCMyStringKey = return[1].KEY // returns "MYSTRING" theCFCMyStringValue = return[1].VALUE // returns "whatever" CFC CFC properties declared in THIS return exactly the way a struct does (including CAPS for key names)

ColdFusion and Ajax Q:What kind of things should I watch out for? A: Yes, there are a few issues you need to know when using CFAJAX. First is the fact that CFAJAX will freeze if you attempt to return a multiline string containing line breaks. You can easily work around that by using the ReReplace function to remove line breaks.

ColdFusion and Ajax Secondly should you wish to use the CFSAVECONTENT tag in your ColdFusion function, you must enclose your output in CFOUTPUT tags. This is because CFAJAX contains the following tag which disables all output except those enclosed in CFOUTPUT tags. Another solution would be to include a CFSETTING tag before and after your block of code, setting the enablecfoutputonly attribute off and on respectively. [... Your code here...]

ColdFusion and Ajax Thirdly (if that’s a word) you may face cross-domain issues when trying to access resources on a different server from your ColdFusion function. By default, CFAJAX uses the HTTP POST method to pass and retrieve data. Doing so will cause the browser to display a “Security violation” popup. You can resolve the issue by using the HTTP GET method by using the following CFAJAX method. DWREngine.setVerb("GET"); //default is POST

ColdFusion and Ajax Lastly we can handle errors by including the following code; Add the following code to the ColdFusion page being used by you CFAJAX code. Add the following code to the error page specified above. alert("#JSStringFormat("Error:" & Error.Diagnostics)#");

ColdFusion and Ajax Q:Can we look at some code? A:Yes! It’s Show And Tell

ColdFusion and Ajax Q: What CFAJAX resources are there? ColdFusion-Part-I