Posting XML Data From the Client to a Server Eugenia Fernandez IUPUI.

Slides:



Advertisements
Similar presentations
CIS 4004: Web Based Information Technology Spring 2013
Advertisements

Java Script Session1 INTRODUCTION.
9. AJAX & RIA. 2 Motto: O! call back yesterday, bid time return. — William Shakespeare.
1 Chapter 12 Working With Access 2000 on the Internet.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
AJAX asynchronous server-client communication. Test.
XMLHttpRequest Object and XML What we should learn in this lesson –What is the XHR object? –How to create the XHR objects? –XHR object properties –XHR.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
INTRODUCTION TO WEB DATABASE PROGRAMMING
The Document Object Model (DOM) & Asynchronous Javascript And XML (AJAX) : an introduction UFCEKG-20-2 : Data, Schemas and Applications.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
CSCI 6962: Server-side Design and Programming Course Introduction and Overview.
Ajax (Asynchronous JavaScript and XML). AJAX  Enable asynchronous communication between a web client and a server.  A client is not blocked when an.
PHP and AJAX ISYS 475. AJAX Asynchronous JavaScript and XML: – JavaScript, Document Object Model, Cascade Style Sheet, XML, server-side script such as.Net,
JavaScript & jQuery the missing manual Chapter 11
Chapter 5 Java Script And Forms JavaScript, Third Edition.
CSCI 6962: Server-side Design and Programming Introduction to AJAX.
Lecture 12 – AJAX SFDV3011 – Advanced Web Development Reference: 1.
Overview of Previous Lesson(s) Over View  ASP.NET Pages  Modular in nature and divided into the core sections  Page directives  Code Section  Page.
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.
XP New Perspectives on XML, 2 nd Edition Tutorial 10 1 WORKING WITH THE DOCUMENT OBJECT MODEL TUTORIAL 10.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
CSCI 6962: Server-side Design and Programming Introduction to Java Server Faces.
06/10/2015AJAX 1. 2 Introduction All material from AJAX – what is it? Traditional web pages and operation Examples of AJAX use Creating.
Working with the XML Document Object Model ©NIITeXtensible Markup Language/Lesson 7/Slide 1 of 44 Objectives In this lesson, you will learn to: *Identify.
 2004 Prentice Hall, Inc. All rights reserved. 1 Chapter 34 - Case Study: Active Server Pages and XML Outline 34.1 Introduction 34.2 Setup and Message.
Client side web programming Introduction Jaana Holvikivi, DSc. School of ICT.
1 Dr Alexiei Dingli XML Technologies XML Advanced.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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)
Ajax XMod for Dummies Building DNN Ajax Modules Without Programming Dave McMullen SoCal DNN Users Group 2/7/07 –
Asynchronous Javascript And XML AJAX : an introduction UFCEUS-20-2 : Web Programming.
Introduction to the Document Object Model Eugenia Fernandez IUPUI.
Producing a high-impact web experience by integrate Macromedia Flash and ASP By Katie Tuttle CS 330: Internet Architecture and Programming Project.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
CISC 3140 (CIS 20.2) Design & Implementation of Software Application II Instructor : M. Meyer Address: Course Page:
INT222 - Internet Fundamentals Shi, Yue (Sunny) Office: T2095 SENECA COLLEGE.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
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.
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.
Web Technology (NCS-504) Prepared By Mr. Abhishek Kesharwani Assistant Professor,UCER Naini,Allahabad.
AJAX CS456 Fall Examples Where is AJAX used? Why do we care?
JavaScript, Sixth Edition Chapter 11 Updating Web Pages with Ajax.
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.
Generating XML Data from a Database Eugenia Fernandez IUPUI.
Ajax SUBMITTED BY NITIN RAMANI C.S.E 3 rd Y 5 th S R.N CS SUBMITTED TO PRO. PUSHPARAJ PATEL SIR.
Introduction to AJAX Pat Morin COMP Outline What is AJAX? – History – Uses – Pros and Cons An XML HTTP Transaction – Creating an XMLHTTPRequest.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
JavaScript and Ajax (Ajax Tutorial)
Understanding XMLHttpRequest
Not a Language but a series of techniques
AJAX AJAX = Asynchronous JavaScript and XML.
Introduction to the Document Object Model
AJAX and REST.
XMLHttp Object.
Web System & Technology
AJAX and JSP ISYS 350.
CSE 154 Lecture 22: AJAX.
JavaScript & AJAX.
ISC440: Web Programming 2 AJAX
JavaScript & jQuery AJAX.
AJAX CS-422 Dick Steflik.
Chengyu Sun California State University, Los Angeles
Chengyu Sun California State University, Los Angeles
AJAX and JSP ISYS 350.
Presentation transcript:

Posting XML Data From the Client to a Server Eugenia Fernandez IUPUI

Client Server XML Example 1. Read catalog 5. Update database 2. Catalog XML 4. Order XML 3. Manipulate XML & build XML data packet Data Source Web Server Client

Why Bother? XML data is manipulated on the client with changes made at the client which reduces the load on the server. Only one update and only the updated information need be sent back to the server. All transfers are done in XML text which are small in size.

Sending XML from Client to Server 1. Client populates a DOMDocument object with XML data to send to the server. 2. Client creates XMLHTTP object, and loads the XML data packet into the XMLHTTP object. 3. Client sends the data to an ASP page at the server. 4. Server executes the ASP page and creates a server-side DOMDocument object. 5. The ASP loads the XML data packet into the server-side DOMDocument object. 6. The ASP processes the data as needed.

Building an XML Data Packet Create a DOMDocument object to hold the XML data from any of the following sources: XML data island at the client a stand-alone XML document a dynamically generated XML document containing a mixture of boilerplate XML, data from XML data islands, and data created from user input at the client

Example: Adding Existing XML Data Island into a DOM Tree 1. Create a DOMDocument object set docSubmit = CreateObject(“MSXML2.DOMDocument”) docSubmit.async = false 2. Access the XML data island set docOrder = xmldso.XMLDocument set nodeOrder = docOrder.selectSingleNode(“//order”)

Example: Adding Existing XML Data Island into a DOM Tree 2 3. Create a copy of the XML data. set sendOrder = nodeOrder.cloneNode(true) The node you obtained is part of an existing DOM tree. The appendChild method will remove the node from the tree it is currently in before adding it to the new DOM tree. Thus you must create a copy of the node using the cloneNode method. The cloneNode method takes a single parameter indicating whether child elements are included in the copy. 4. Add the copied node to the XML data packet docSubmit.documentElement.appendChild sendOrder

Create the XMLHTTP Object Create a MSXML2.XMLHTTP object Open the request, specifying Delivery method, url, async flag UserID and password (if needed) Set poster = CreateObject(“MSXML2.XMLHTTP”) poster.open “POST”, “CustomerOrder.asp”, False

Sending Data to the Server Send the XML data poster.send docSubmit Check the readyState property of the Document, which tells if the server has built the Response object

XMLHTTP Properties Syntax poster.Open http-method, url, [async, userID, pw] Parameters http-method: GET or POST url: the url that will receive the XML data at the server, typically an ASP or CGI page async: True or False indicating whether the request is asynchronous. If asynchronous (true) the client will not wait for a response when sending the data. If synchronous (false), the client waits for a response before continuing. userID: the userID, if any, required for authentication at the server pw: the password, if any, required for authentication at the server

ReadyState Values Can use this value in a script to check state of document state = doc.readyState Can also use onReadyStateChange property to check state whenever it changes and inform client of progress doc.onReadyStateChange = GetRef(“CheckState”) ValueMeaning 0Response object is created, but not yet loaded 1Document is being loaded 2Document has been loaded and parsing is underway 3Parsing is partially done so partial data is available to the client 4Document has been completely parsed and is fully available to the client

Loading XML Data on the Server Create a DOMDocument object set docReceived = CreateObject(“MSXML2.DOMDocument”) Load the XML data from the Request object docReceived.async = false docReceived.load Request Access XML data in the DOMDocument object set rootNode = docReceived.documentElement

Manipulating XML at the Server Once an XML document has been loaded into a DOMDocument object, you can use DOM to access and manipulate the XML data. For example, the following ASP script obtains a collection of all elements in a document and uses a loop to navigate through the collection set listBookOrder = docReceived.selectNodes(“//orderitem”) for each node in listBookOrder ‘ process a node (representing a bookOrder element) Next

Updating the Database Open an ADO connection to the database Write ASP script to query and update the database as needed, e.g. insert new record. set listBookOrder = docReceived.selectNodes(“//orderitem”) for each node in listBookOrder ‘get details for this node & insert new record isbn = node.getAttribute(“isbn”) price = node.getAttribute(“price”) qty = node.getAttribute(“qty”) connName.execute (“Insert into orderItems VALUES ” &_ isbn & “,” & price & “, “ & qty) Next

Building an Response Response can be built in many ways Plain Text HTML page XML document HTML page with an XML data island

Building an HTML Response Example Confirmation of Order <% for each node in listOrderItem title = node.getAttribute(“title”) set quantityNode = node.selectSingleNode(“quantity”) quantity = quantityNode.firstChild.nodeValue %>,

Responding with Static XML set docResponse = CreateObject(“MSXML2.DOMDocument”) docResponse.async = false docResponse.load “MyFixedResponse.xml” Response.ContentType = “text/xml” Response.Save docResponse

Retrieving an HTML Response Use the responseText property of XMLHTTP Assign the response string to an HTML element Example Set poster = CreateObject(“MSXML2.XMLHTTP”) poster.open “POST”, “CustomerOrder.asp”, False poster.send docSubmit displayArea.innerHTML = poster.responseText

Retrieving an XML Response Use the responseXML property of XMLHTTP Manipulate using DOM Example Set poster = CreateObject(“MSXML2.XMLHTTP”) poster.open “POST”, “CustomerOrder.asp”, False poster.send docSubmit set docResponse = poster.responseXML set listItem = docResponse.selectNodes(“//item”)

Source “Building XML-Based Web Applications” a Microsoft Certified Course.