Ajax Programming for the Absolute Beginner

Total Page:16

File Type:pdf, Size:1020Kb

Ajax Programming for the Absolute Beginner Ajax Programming for the Absolute Beginner Jerry Lee Ford, Jr. Course Technology PTR A part of Cengage Learning Australia, Brazil, Japan, Korea, Mexico, Singapore, Spain, United Kingdom, United States Ajax Programming for the Absolute © 2009 Course Technology, a part of Cengage Learning. Beginner: Jerry Lee Ford, Jr. ALL RIGHTS RESERVED. No part of this work covered by the copyright Publisher and General Manager, Course herein may be reproduced, transmitted, stored, or used in any form or by Technology PTR: Stacy L. Hiquet any means graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, Associate Director of Marketing: information networks, or information storage and retrieval systems, except Sarah Panella as permitted under Section 107 or 108 of the 1976 United States Copyright Manager of Editorial Services: Act, without the prior written permission of the publisher. Heather Talbot Marketing Manager: Mark Hughes For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 Acquisitions Editor: Mitzi Koontz For permission to use material from this text or product, submit all Project Editor: Jenny Davidson requests online at cengage.com/permissions Further permissions questions can be emailed to [email protected] Technical Reviewer: Keith Davenport PTR Editorial Services Coordinator: Jen Blaney All trademarks are the property of their respective owners. Library of Congress Control Number: 2008928834 Interior Layout Tech: Value-Chain ISBN-13: 978-1-59863-564-5 Cover Designer: Mike Tanamachi ISBN-10: 1-59863-564-6 Indexer: Katherine Stimson eISBN-10: 1-43545-531-2 Course Technology Proofreader: Sara Gullion 25 Thomson Place Boston, MA 02210 USA Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: international.cengage.com/region Cengage Learning products are represented in Canada by Nelson Education, Ltd. For your lifelong learning solutions, visit courseptr.com Visit our corporate website at cengage.com Printed in Canada 1 2 3 4 5 6 7 11 10 09 To my mother and father for always being there, and to my wonderful children, Alexander, William, and Molly, and my beautiful wife, Mary. ACKNOWLEDGMENTS here are several individuals to whom I owe many thanks for their help and Tassistance in the development of this book. I’ll start by thanking Mitzi Koontz, who served as the book’s acquisitions editor. Special thanks also go out to Jenny Davidson for serving as the book's project editor. I also want to thank Keith Davenport for all the valuable input and advice. In addition, I would like to thank everyone else at Course Technology PTR for all their hard work. ABOUT THE AUTHOR erry Lee Ford, Jr. is an author, educator, and an IT professional with over J18 years of experience in information technology, including roles as an automation analyst, technical manager, technical support analyst, au- tomation engineer, and security analyst. He is the author of 28 books and co-author of two additional books. His published works include AppleScript Studio Program- ming for the Absolute Beginner, Microsoft Windows PowerShell Programming for the Absolute Beginner, Microsoft Visual Basic 2005 Express Edition Programming for the Abso- lute Beginner, Microsoft VBScript Professional Projects, Microsoft Windows Shell Scripting and WSH Administrator’s Guide, Microsoft Windows Shell Script Programming for the Ab- solute Beginner, Learn JavaScript in a Weekend, Second Edition, and Microsoft Windows XP Professional Administrator’s Guide. Jerry has a master’s degree in business adminis- tration from Virginia Commonwealth University in Richmond, Virginia, and he has over five years of experience as an adjunct instructor teaching networking courses in information technology. This page intentionally left blank Table of Contents Introduction.......................................................... xiv Part I Introducing Ajax....................................................... 1 Chapter 1 An Ajax Overview...................................................... 3 Project Preview: The Joke of the Day Application......................................................... 4 Introducing Ajax.................................................................................................................... 5 Ajax Technologies ......................................................................................................... 6 Traditional Web Development Versus Ajax Development................................. 6 Examples of Real-World Ajax Applications and Websites.......................................... 9 Search Engine Makeovers............................................................................................ 9 Suggest Styled Applications ..................................................................................... 10 Google Maps.................................................................................................................. 13 Netflix............................................................................................................................. 14 Virtual Desktop Applications................................................................................... 14 Photo Management Using Flickr............................................................................. 16 Ajax Instant Message Applications......................................................................... 16 Online Calendars......................................................................................................... 17 Back to the Joke of the Day Application........................................................................ 18 Designing the Application........................................................................................ 18 The Final Result ........................................................................................................... 25 Summary................................................................................................................................ 26 Part II Learning JavaScript and the DOM....................... 27 Chapter 2 An Introduction to JavaScript............................. 29 Project Preview: The Number Guessing Game............................................................. 29 JavaScript—Ajax’s Programming Language.................................................................. 31 A Little JavaScript Background Information........................................................ 31 Browser Compatibility Issues................................................................................... 32 viii Ajax Programming for the Absolute Beginner Working with JavaScript.................................................................................................... 33 Creating a Simple JavaScript.................................................................................... 34 Executing Your JavaScript......................................................................................... 34 Four Ways of Working with JavaScript.......................................................................... 35 Embedding JavaScripts in the HEAD Section....................................................... 35 Embedding JavaScripts in the BODY Section....................................................... 37 Placing JavaScripts in External Files ...................................................................... 38 Embedding JavaScripts in HTML Tags.................................................................... 38 Understanding JavaScript Statement Syntax ...................................................... 39 Dealing with Browsers That Do Not Support JavaScript .................................. 39 Documenting Your Scripts Using Comments...................................................... 40 Working with Different Types of Values....................................................................... 41 Creating JavaScript Variables................................................................................... 41 Assigning Variable Names ........................................................................................ 42 Understanding Variable Scope ................................................................................ 42 Working with Local Variables.................................................................................. 42 Doing a Little Math..................................................................................................... 43 Assigning and Modifying Variable Values............................................................ 44 Applying Conditional Logic.............................................................................................. 47 Introducing the if Statement................................................................................... 47 Multi-line if Statements............................................................................................. 48 Providing for Alternative Conditions .................................................................... 48 Nesting if Statements................................................................................................. 49 Working with the switch Statement.....................................................................
Recommended publications
  • Differential Fuzzing the Webassembly
    Master’s Programme in Security and Cloud Computing Differential Fuzzing the WebAssembly Master’s Thesis Gilang Mentari Hamidy MASTER’S THESIS Aalto University - EURECOM MASTER’STHESIS 2020 Differential Fuzzing the WebAssembly Fuzzing Différentiel le WebAssembly Gilang Mentari Hamidy This thesis is a public document and does not contain any confidential information. Cette thèse est un document public et ne contient aucun information confidentielle. Thesis submitted in partial fulfillment of the requirements for the degree of Master of Science in Technology. Antibes, 27 July 2020 Supervisor: Prof. Davide Balzarotti, EURECOM Co-Supervisor: Prof. Jan-Erik Ekberg, Aalto University Copyright © 2020 Gilang Mentari Hamidy Aalto University - School of Science EURECOM Master’s Programme in Security and Cloud Computing Abstract Author Gilang Mentari Hamidy Title Differential Fuzzing the WebAssembly School School of Science Degree programme Master of Science Major Security and Cloud Computing (SECCLO) Code SCI3084 Supervisor Prof. Davide Balzarotti, EURECOM Prof. Jan-Erik Ekberg, Aalto University Level Master’s thesis Date 27 July 2020 Pages 133 Language English Abstract WebAssembly, colloquially known as Wasm, is a specification for an intermediate representation that is suitable for the web environment, particularly in the client-side. It provides a machine abstraction and hardware-agnostic instruction sets, where a high-level programming language can target the compilation to the Wasm instead of specific hardware architecture. The JavaScript engine implements the Wasm specification and recompiles the Wasm instruction to the target machine instruction where the program is executed. Technically, Wasm is similar to a popular virtual machine bytecode, such as Java Virtual Machine (JVM) or Microsoft Intermediate Language (MSIL).
    [Show full text]
  • Dynamic Web Pages with the Embedded Web Server
    Dynamic Web Pages With The Embedded Web Server The Digi-Geek’s AJAX Workbook (NET+OS, XML, & JavaScript) Version 1.0 5/4/2011 Page 1 Copyright Digi International, 2011 Table of Contents Chapter 1 - How to Use this Guide ............................................................................................................... 5 Prerequisites – If You Can Ping, You Can Use This Thing! ..................................................................... 5 Getting Help with TCP/IP and Wi-Fi Setup ............................................................................................ 5 The Study Guide or the Short Cut? ....................................................................................................... 5 C Code ................................................................................................................................................... 6 HTML Code ............................................................................................................................................ 6 XML File ................................................................................................................................................. 6 Provide us with Your Feedback ............................................................................................................. 6 Chapter 2 - The Server-Client Relationship ................................................................................................... 7 Example – An Analogy for a Normal HTML page .................................................................................
    [Show full text]
  • Attacking AJAX Web Applications Vulns 2.0 for Web 2.0
    Attacking AJAX Web Applications Vulns 2.0 for Web 2.0 Alex Stamos Zane Lackey [email protected] [email protected] Blackhat Japan October 5, 2006 Information Security Partners, LLC iSECPartners.com Information Security Partners, LLC www.isecpartners.com Agenda • Introduction – Who are we? – Why care about AJAX? • How does AJAX change Web Attacks? • AJAX Background and Technologies • Attacks Against AJAX – Discovery and Method Manipulation – XSS – Cross-Site Request Forgery • Security of Popular Frameworks – Microsoft ATLAS – Google GWT –Java DWR • Q&A 2 Information Security Partners, LLC www.isecpartners.com Introduction • Who are we? – Consultants for iSEC Partners – Application security consultants and researchers – Based in San Francisco • Why listen to this talk? – New technologies are making web app security much more complicated • This is obvious to anybody who reads the paper – MySpace – Yahoo – Worming of XSS – Our Goals for what you should walk away with: • Basic understanding of AJAX and different AJAX technologies • Knowledge of how AJAX changes web attacks • In-depth knowledge on XSS and XSRF in AJAX • An opinion on whether you can trust your AJAX framework to “take care of security” 3 Information Security Partners, LLC www.isecpartners.com Shameless Plug Slide • Special Thanks to: – Scott Stender, Jesse Burns, and Brad Hill of iSEC Partners – Amit Klein and Jeremiah Grossman for doing great work in this area – Rich Cannings at Google • Books by iSECer Himanshu Dwivedi – Securing Storage – Hackers’ Challenge 3 • We are
    [Show full text]
  • Mastering Ajax, Part 4: Exploiting DOM for Web Response Convert HTML Into an Object Model to Make Web Pages Responsive and Interactive
    Mastering Ajax, Part 4: Exploiting DOM for Web response Convert HTML into an object model to make Web pages responsive and interactive Skill Level: Introductory Brett McLaughlin Author and Editor O'Reilly Media Inc. 14 Mar 2006 The great divide between programmers (who work with back-end applications) and Web programmers (who spend their time writing HTML, CSS, and JavaScript) is long standing. However, the Document Object Model (DOM) bridges the chasm and makes working with both XML on the back end and HTML on the front end possible and an effective tool. In this article, Brett McLaughlin introduces the Document Object Model, explains its use in Web pages, and starts to explore its usage from JavaScript. Like many Web programmers, you have probably worked with HTML. HTML is how programmers start to work on a Web page; HTML is often the last thing they do as they finish up an application or site, and tweak that last bit of placement, color, or style. And, just as common as using HTML is the misconception about what exactly happens to that HTML once it goes to a browser to render to the screen. Before I dive into what you might think happens -- and why it is probably wrong -- I want you need to be clear on the process involved in designing and serving Web pages: 1. Someone (usually you!) creates HTML in a text editor or IDE. 2. You then upload the HTML to a Web server, like Apache HTTPD, and make it public on the Internet or an intranet. Exploiting DOM for Web response Trademarks © Copyright IBM Corporation 2006 Page 1 of 19 developerWorks® ibm.com/developerWorks 3.
    [Show full text]
  • The Implementation of Large Video File Upload System Based on the HTML5 API and Ajax Yungeng Xu , Sanxing
    Joint International Mechanical, Electronic and Information Technology Conference (JIMET 2015) The Implementation of Large Video File Upload System Based on the HTML5 API and Ajax Yungeng Xu1, a, Sanxing Cao2, b 1 Department of Science and Engineering, Communication University of China, Beijing 2 New Media Institute, Communication University of China, Beijing a b [email protected], [email protected] Keywords: HTML5; File upload; Shell; XMLHttpRequest Abstract. The function of upload file is an important web page designs. Traditional file upload function for file upload function by HTML form and $_FILES system function, has the advantages of convenience, can cope with a relatively small file upload. The traditional HTML way has been difficult to meet the upload of the oversized file. Service not only to open a link waiting for this file is uploaded, but also to allocate the same size of memory to save this file. In the case of large concurrency may cause a great pressure on the server. This article is the use of HTML5 File API to upload video files in the original form on the basis of form, use the function of slice inside the HTML5 file API for the split file upload, to achieve the result of no refresh upload files. Have a valid practical significance. Introduction With the development of web technology, watch videos on the website has become an important forms of entertainment in the people's daily life. Internet video give people a great deal of freedom to choose the way of entertainment, not limited to the live TV mode. People can watch the video on the webpage.
    [Show full text]
  • Navigation and Interaction in Urban Environments Using Webgl
    NAVIGATION AND INTERACTION IN URBAN ENVIRONMENTS USING WEBGL Mar´ıa Dolores Robles-Ortega, Lidia Ortega, Francisco R. Feito and Manuel J. Gonz´alez Department of Computer Science, University of Ja´en, Paraje Las Lagunillas, s/n 23071 Ja´en, Spain Keywords: WebGL, X3DOM, 3D Urban Scenes, X3D, Web System. Abstract: The process of rendering and interacting with large scenes in web systems is still an open problem in 3D urban environments. In this paper we propose a prototype to visualize a city model in a client-server architecture using open-source technologies like WebGL and X3DOM. Moreover, free navigation around the scene is allowed and users are able to obtain additional information when interacting with buildings and street furniture. To achieve this objective, a MySQL geodatabase has been designed to store both geometric and non-geometric urban information. Therefore, the extra data about the urban elements is obtained through queries in the database. The communication process between MySQL and the X3D model is performed by Ajax. 1 INTRODUCTION model. Evidently, the language used to implement the 3D City Modeling (3DCM) is a research area of great system should fulfill all the requirements described interest with a wide range of applications such as ur- above. Nowadays there are some approaches, like the ban planning, architecture, emergency management, ISO standard language X3D (W3C, 2004) for render- or engineering and construction. The accessibility ing 3D scenes in the Web, but they need the installa- of these tools through the Internet would be a desir- tion of specific plugins. To avoid this drawback, some able option.
    [Show full text]
  • AJAX Xmlhttprequest
    AAJJAAXX -- XXMMLLHHTTTTPPRREEQQUUEESSTT http://www.tutorialspoint.com/ajax/what_is_xmlhttprequest.htm Copyright © tutorialspoint.com The XMLHttpRequest object is the key to AJAX. It has been available ever since Internet Explorer 5.5 was released in July 2000, but was not fully discovered until AJAX and Web 2.0 in 2005 became popular. XMLHttpRequest XHR is an API that can be used by JavaScript, JScript, VBScript, and other web browser scripting languages to transfer and manipulate XML data to and from a webserver using HTTP, establishing an independent connection channel between a webpage's Client-Side and Server-Side. The data returned from XMLHttpRequest calls will often be provided by back-end databases. Besides XML, XMLHttpRequest can be used to fetch data in other formats, e.g. JSON or even plain text. You already have seen a couple of examples on how to create an XMLHttpRequest object. Listed below is listed are some of the methods and properties that you have to get familiar with. XMLHttpRequest Methods abort Cancels the current request. getAllResponseHeaders Returns the complete set of HTTP headers as a string. getResponseHeaderheaderName Returns the value of the specified HTTP header. openmethod, URL openmethod, URL, async openmethod, URL, async, userName openmethod, URL, async, userName, password Specifies the method, URL, and other optional attributes of a request. The method parameter can have a value of "GET", "POST", or "HEAD". Other HTTP methods, such as "PUT" and "DELETE" primarilyusedinRESTapplications may be possible. The "async" parameter specifies whether the request should be handled asynchronously or not. "true" means that the script processing carries on after the send method without waiting for a response, and "false" means that the script waits for a response before continuing script processing.
    [Show full text]
  • The Use of Scalable Vector Graphics in Flexible, Thin-Client Architectures for Tv Navigation
    THE USE OF SCALABLE VECTOR GRAPHICS IN FLEXIBLE, THIN-CLIENT ARCHITECTURES FOR TV NAVIGATION Michael Adams Solution Area TV, Ericsson Abstract Support rapid development of new applications without the need for new Today’s subscribers are demanding more software download to the set-top and more from their service providers: Enable personalization of a service to each subscriber’s preferences Personalization: New behaviors from a Allow full customization of the user- new generation of “digital natives”, (who interface, including branding expect the service to adapt to them!), Allow the use of third-party developers, powerful search capabilities, and using Web 2.0 service creation methods recommendations engines. Provide set-top independence and Communication: Multitasking, social multiplatform portability networking, and sharing the viewing Decouple CA/DRM certification from new experience through chat and instant features and applications development messaging Interactivity: Polls, games, and enhanced INTRODUCTION programming Today’s subscribers are demanding more And subscribers want all the above and more from their service providers. What services and features to be delivered as a they want can be grouped into three main single, integrated service experience across categories: any device, anywhere, and at anytime! Personalization The Internet has shown how to deliver all Communication kinds of services by means of thin-client Interactivity approaches using the Representational State Transfer (REST) model. Meanwhile, most Personalization deployed cable architectures still rely on a “state-full”, thick-client approach. I want my service to adapt to my needs. I need recommendations to sort my Can thin-client architectures really “wheat” from the “chaff”. satisfy large cable system requirements for I want to watch anything, on any device, performance, scalability, high-availability, at any time, anywhere.
    [Show full text]
  • A Websocket-Based Approach to Transporting Web Application Data
    A WebSocket-based Approach to Transporting Web Application Data March 26, 2015 A thesis submitted to the Division of Graduate Studies and Research of the University of Cincinnati in partial fulfillment of the requirements for the degree of MASTER OF SCIENCE in the Department of Computer Science of the College of Engineering and Applied Science by Ross Andrew Hadden B.S., University of Cincinnati, Cincinnati, Ohio (2014) Thesis Adviser and Committee Chair: Dr. Paul Talaga Committee members: Dr. Fred Annexstein, Professor, and Dr. John Franco, Professor Abstract Most web applications serve dynamic data by either deferring an initial page response until the data has been retrieved, or by returning the initial response immediately and loading additional content through AJAX. We investigate another option, which is to return the initial response immediately and send additional content through a WebSocket connection as the data becomes available. We intend to illustrate the performance of this proposition, as compared to popular conventions of both a server- only and an AJAX approach for achieving the same outcome. This dissertation both explains and demonstrates the implementation of the proposed model, and discusses an analysis of the findings. We use a Node.js web application built with the Cornerstone web framework to serve both the content being tested and the endpoints used for data requests. An analysis of the results shows that in situations when minimal data is retrieved after a timeout, the WebSocket method is marginally faster than the server and AJAX methods, and when retrieving populated files or database records it is marginally slower. The WebSocket method considerably outperforms the AJAX method when making multiple requests in series, and when making requests in parallel the WebSocket and server approaches both outperform AJAX by a tremendous amount.
    [Show full text]
  • Making Phone Calls from Blazor Webassembly with Twilio Voice
    © Niels Swimberghe https://swimburger.net - @RealSwimburger 1 About me • Niels Swimberghe aka Swimburger • Grew up in Belgium, working in USA • .NET Developer / Tech Content Creator • Blog at swimbuger.net • Twitter: @RealSwimburger • Company: 2 Programmatic communication using HTTP Webhooks Example TwiML Sample: https://demo.twilio.com/welcome/voice/ Based on in-depth guide on Twilio Blog Check out guide at Twilio Blog Application • Out of the box Blazor WebAssembly application • Phone dialer • Initiate phone calls from browser • Receive phone calls in browser Recommended architecture Demo architecture Demo architecture Auth flow 1. Ajax HTTP Request JWT token 2. Server generates JWT token and sends token in HTTP response 3. Twilio JavaScript SDK establishes bidirectional connection with Twilio over WebSocket Incoming call flow 1. Phone calls Twilio Phone Number 2. Twilio sends HTTP request to your webhook asking for instructions 3. Webhook responds with TwiML instructions Incoming call flow Webhook responds with TwiML instructions Incoming call flow 4. Twilio dials client 5. Client accepts incoming connection => VoIP established Outgoing call flow 1. Client connects to Twilio with To parameter 2. Twilio sends HTTP request to your webhook asking for instructions 3. Webhook responds with TwiML instructions Outgoing call flow Webhook responds with TwiML instructions Outgoing call flow 4. Twilio dials phone number 5. Phone accepts incoming connection => VoIP established Let’s see how its built Step 1: Create Twilio resources • You need to
    [Show full text]
  • Lecture 10 – Ajax and Jquery
    Lecture 10 – Ajax and jQuery INLS 760 Web Databases Spring 2013 Rob Capra AJAX What is AJAX? 1. The “original” Ajax… is in Agamemnon’s army 2. Another Ajax… is “stronger than dirt” 3. Asynchronous JavaScript and XML Where can I get Ajax? 1. Homer’s Iliad 2. Try the grocery store 3. There is nothing to “get” support is built-in to modern browsers. Ajax is a programming technique. 2 What does AJAX do? • Traditional use of HTTP causes pages to be reloaded when data is exchanged • AJAX uses JavaScript’s XMLHttpRequest method to exchange data with the server without reloading the current page. – This enables quick, small transactions – Client can communicate more often with the server – More flexible user-interfaces can be built – Web applications can look/act more like desktop apps 3 Digging Deeper • Traditional HTTP communication – User clicks a link or presses a form button – Client browser makes an HTTP request using either GET or POST – Server processes request and sends a response – Browser loads the response in a new web page 4 Digging Deeper • AJAX – JavaScript event fires • calls user defined JavaScript function – Client browser makes a request using XMLHttpRequest – Client sets a handler to process the response when it arrives • This communication is asynchronous, so response could arrive whenever – When the response arrives, a client handler does something • For example, update just a PART of the page 5 “Real-World” Example • Google Suggest 6 Simple Example – Client Side <form name="myForm"> Name: <input type="text" onkeyup="ajaxFunction();"
    [Show full text]
  • Rich Web Applications with Java and AJAX
    Rich Web Applications with Java and AJAX June 2005 Stephen Maryka CTO ICEsoft Technologies Inc. The Evolution of the Enterprise Application Is evolution really circular? Or, maybe it’s a never-ending spiral. This appears to be the case when we examine the history of the enterprise software application. In the early era of enterprise computing there were no trade-offs made with regard to an appropriate application model. There was only one option—a thin-client model leveraging centralized servers and delivering presentation to the user via a dumb terminal. With the onset of the personal computer, the model changed, and power to the desktop had a strong evolutionary effect on the application model, moving it away from centralized computing toward a distributed model where individual computers hosted their own set of applications. This fat-client model pushed computation and presentation to the client. With advancement in graphics technologies, it became feasible to provide the user with a rich interactive presentation environment for applications. But these advancements did not come for free. Power to the desktop resulted in skyrocketing costs for deployment, management and maintenance of applications. Total cost of ownership for applications within the enterprise increased dramatically. Next came the Internet era, into which the web application was born, and we spiraled back to a thin-client model. This time around, the application’s presentation was delivered as markup (HTML specifically) and the web browser (the modern dumb terminal) rendered that markup to generate the user presentation for the application. For the enterprise, this new thin-client model reversed the total cost of ownership trend from the previous era, but again, not for free.
    [Show full text]