Basic HTML swap with AJAX. Lets get our beloved html for our llama site. Open the index.html page and add a class to our navigation links. Then lets add.

Slides:



Advertisements
Similar presentations
PART IV - EMBED VIDEO, AUDIO, AND DOCUMENTS. Find a video on Youtube.com: Search for a video, then look for the Embed code. Copy this code into the HTML/JavaScript.
Advertisements

JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
In this lecture, you will learn: ❑ How to link between pages of your site ❑ How to link to other sites ❑ How to structure the folders on your web site.
AJAX Presented by: Dickson Fu Dimas Ariawan Niels Andreassen Ryan Dial Jordan Nielson CMPUT 410 University of Alberta 2006.
Inline, Internal, and External FIle
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
JQuery CS 268. What is jQuery? From their web site:
Win8 on Intel Programming Course Modern UI : Features Cédric Andreolli Intel Software.
HTML & CSS A brief introduction. OUTLINE 1.What is HTML? 2.What is CSS? 3.How are they used together? 4.Troubleshooting/Common problems 5.More resources.
IPUB 100 Lesson 2 Instructor Mark Lamontagne Homework Review.
1 CS 3870/CS 5870 Static and Dynamic Web Pages ASP.NET and IIS.
ACM Web Development Workshop - PHP By Luis Torres.
JavaScript & jQuery the missing manual Chapter 11
JQuery Page Slider. Our goal is to get to the functionality of the Panic Coda web site.Panic Coda web site.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Links in HTML. Hyperlinks or links Millions of linked web pages make up the World Wide Web Used to connect a web page to another web page on the same.
CSS Sprites. What are sprites? In the early days of video games, memory for graphics was very low. So to make things load quickly and make graphics look.
Unobtrusive JavaScript
Lesson 19. JavaScript errors Since JavaScript is an interpreted language, syntax errors will usually cause the script to fail. Both browsers will provide.
1 rfXcel Confidential Copyright 2007 Web Technology JavaScript 12/10/07.
Bill's Amazing Content Rotator jQuery Content Rotator.
Interacting with a Web Page using JavaScript Mat Kelly GTAI Presentation January 10, 2014.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
WEB DESIGN UNIT 2 Unit 2 Module 2-5. WHAT HAVE YOU LEARNED?  What is the title tag do? Where does it show?  What are the tags that need to be on every.
What is Java Script? An extension to HTML. An extension to HTML. Allows authors to incorporate some functionality in their web pages. (without using CGI.
Ajax - 1h. AJAX IS: A browser technology A technology that uses only JavaScript in the browser page A very efficient way of updating information A way.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Rich Internet Applications 4. Ajax. What is Ajax? Asynchronous JavaScript and XML Term coined in 2005 by Jesse James Garrett
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
HTML Concepts and Techniques Fifth Edition Chapter 6 Using Frames in a Web Site.
Very Basic AJAX. Ajax the Great In Homer's Iliad he is described as of great stature, colossal frame, the tallest and strongest of all the Achaeans, second.
Introduction to Client Side Scripting CS Client Side Scripting Client side means the Browser is interpreting the script Script is downloaded with.
Lecture 9: AJAX, Javascript review..  AJAX  Synchronous vs. asynchronous browsing.  Refreshing only “part of a page” from a URL.  Frameworks: Prototype,
audio video object Options: controls autoplay Need to define height and width Options: controls autoplay.
JavaScript - Basic Concepts Prepared and Presented by Hienvinh Nguyen, Afshin Tiraie.
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
AJAX 10 Most Common Mistakes. 1. Not giving immediate visual cues for clicking widgets. If something I'm clicking on is triggering Ajax actions, you have.
UNIT 2 UNIT 2 Module 3: HTML Lists Overview. List There are two common types of HTML lists Ordered list numbered Unordered list bullet points.
School of Computing and Information Systems CS 371 Web Application Programming AJAX.
1 Javascript DOM Peter Atkinson. 2 Objectives Understand the nature and structure of the DOM Add and remove content from the page Access and change element.
PHP “Personal Home Page Hypertext Pre-processor” (a recursive acronym) Allows you to create dynamic web pages and link web pages to a database.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
Web Technologies Lecture 7 Synchronous vs. asynchronous.
JavaScript Challenges Answers for challenges
Event Handling. Objectives Using event handlers Simulating events Using event-related methods.
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (NON-Audio version) © Dr. David C. Gibbs WDMD.
Creating Web Documents: JavaScript Ftp / file management: review Introduction to JavaScript Sources Homework: start review for midterm, work on Project.
Open the index.html Open this PowerPoint from the S Drive IDT folder Chapman Images.ppt.
IN THIS LESSON, WE WILL BECOME FAMILIAR WITH HTML AND BEGIN CREATING A WEB PAGE IN YOUR COMPUTER HTML – the foundation.
Ajax Dice Game Part 1. We saw that we could use the jQuery load() function, to dynamically load a piece of an html document into another html document.
Check Boxes. 2 Check boxes  Image from:  HTML:  Each box gets it's own.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
JQuery Animation. If you look at example1.html, you will see that it is a basic web page with links to the jquery library, and a script.js file and some.
JQUERY AND AJAX
1 Using jQuery JavaScript & jQuery the missing manual (Second Edition)
11 jQuery Web Service Client. 22 Objectives You will be able to Use JSON (JavaScript Object Notation) for communcations between browser and server methods.
JavaScript, Third Edition 1 SELECTION LIST Demo. JavaScript, Third Edition 2 Description This web page will edit the slection to ensure an option was.
Making the website. Get your folders sorted first Create a new folder in “N” called “My hockey website” Create folders inside called “Documents”, “images”
Not a Language but a series of techniques
CS 371 Web Application Programming
>> PHP: HTML Integration
Getting web pages First we need to get the webpage by issuing a HTTP request. The best option for this is the requests library that comes with Anaconda:
PHP and Forms.
HTML Structure.
Introduction to Programming and JavaScript
Introduction to JavaScript
Presentation transcript:

Basic HTML swap with AJAX

Lets get our beloved html for our llama site. Open the index.html page and add a class to our navigation links. Then lets add a link to our javascript file. Go ahead and create the new file called script.js and save it into the right folder.

On our script page, we add our initAll() function. In that function we will loop through all the links on the page looking for links that have a class name of "getpage" Then we attach an onclick handler that runs the getData program.

window.onload = initAll; function initAll() { var allLinks = document.getElementsByTagName("A"); for (i=0; i<allLinks.length; i++) { if (allLinks[i].className == "getpage") { allLinks[i].onclick = getData; } } } Copy and paste this into the script.js file.

Then we have to set up our httpRequest object. This function is exactly the same as before. It really does not change. You can just copy and paste it.

function getRequest() { try { req = new XMLHttpRequest(); } catch(err1) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(err3) { req = false; } } } return req; } This is the next function for the script.js file.

Then comes the getData() function which uses the request we set up and is checking the server for changes in its state. This function calls the useResponse function. function getData() { req = getRequest(); var url = this.href; req.onreadystatechange = useResponse; req.open("GET", url, true); req.send(null); return false; }

The useResponse function is the function that actually replaces the text in the maincontent div on the page. Essentially, we are going to use our AJAX engine to replace the content of the #maincontent div on the fly without even reloading the page.

function useResponse() { if(req.readyState == 4) { if(req.status == 200) { document.getElementById("maincontent").innerHTML = req.responseText; } } else { document.getElementById("maincontent").innerHTML = ' '; } }

For each of our other pages in the site, we need to remove everything from the file except the content of the main content div, including the opening and closing tags for the element. We only want the guts. I have put comments in the pages telling you what to remove. The code above is going to replace the contents of that div with the response text inside the the request object.

Finally, when the page first loads, it will load content normally found inside that maincontent div as usual. But now that we have wiped that content out and replaced it with the content from other pages, we need to have a way to put it back. To do this, I included a file called home.html, which contains the content from the maincontent div of the index.html file. Link to that file in the navigation instead. Now when you click the home link, it will replace the content in the div with the home page content. NOTE: We are done with this, but to test it, it must run from a server! The request status stuff we wrote with javascript needs a response from an actual server. We can use MAMP, XAMPP or WAMP to run it locally, or we can put it on an actual web server.