Inserting an inline frame within a section of text allows you to insert an HTML

Inserting an inline frame within a section of text

This preview shows page 20 - 27 out of 81 pages.

Inserting an inline frame within a section of text allows you to insert an HTML document in the middle of another, may be aligned with surrounding text, etc. For the specification of the iFrame tag see: We will focus on using XMLHttpRequest
Image of page 20
© 2007-2012 Marco Papa & Ellis Horowitz 21 Web Remoting using XMLHttpRequest Creating an instance of the XMLHttpRequest object requires branching syntax to account for browser differences in the way instances of the object are generated. For Safari and Mozilla, a simple call to the object's constructor function does the job: var req = new XMLHttpRequest(); For the ActiveX branch, pass the name of the object to the ActiveX constructor: var req = new ActiveXObject("Microsoft.XMLHTTP"); The object reference returned by both constructors is to an abstract object that works entirely out of view of the user. Its methods control all operations, while its properties hold, among other things, various data pieces returned from the server.
Image of page 21
© 2007-2012 Marco Papa & Ellis Horowitz 22 XMLHttpRequest Object Methods
Image of page 22
© 2007-2012 Marco Papa & Ellis Horowitz 23 XMLHttpRequest Object Methods (cont’d) • Of the methods shown in the Table on the previous slide, the open() and send() methods are the ones you'll likely use most. • open() sets the scene for an upcoming operation. Two required parameters are the HTTP method you intend for the request and the URL for the connection. For the method parameter, use "GET" on operations that are primarily data retrieval requests; use "POST" on operations that send data to the server, especially if the length of the outgoing data is potentially greater than 512 bytes. The URL may be either a complete or relative URL. • It is safer to send asynchronously and design your code around the onreadystatechange event for the request object.
Image of page 23
© 2007-2012 Marco Papa & Ellis Horowitz 24 XMLHttpRequest Example Code var req; function loadXMLDoc(url) { req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } if(req) { req.onreadystatechange = processReqChange; req.open("GET", url, true); req.send(""); } } This code instantiates an XmlHttpRequest object depending upon the browser
Image of page 24
© 2007-2012 Marco Papa & Ellis Horowitz 25 XMLHttpRequest Object Properties
Image of page 25
© 2007-2012 Marco Papa & Ellis Horowitz 26 XMLHttpRequest Object Properties (cont’d) Use the readyState property inside the event handler function that processes request object state change events. While the object may undergo interim state changes during its creation and processing, the value that signals the completion of the transaction is 4.
Image of page 26
Image of page 27

You've reached the end of your free preview.

Want to read all 81 pages?

  • Fall '07
  • Papa
  • Ajax, Marco Papa

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes