Introduction to Document Object Model Every thing in browsing - - PowerPoint PPT Presentation

introduction to document object model every thing in
SMART_READER_LITE
LIVE PREVIEW

Introduction to Document Object Model Every thing in browsing - - PowerPoint PPT Presentation

Introduction to Document Object Model Every thing in browsing window is Object DOM is an API for valid HTML and well formed XML documents EXtensible Markup Language XML is a markup language much like HTML XML was designed


slide-1
SLIDE 1

Introduction to

slide-2
SLIDE 2

 Document Object Model  Every thing in browsing window is Object  DOM is an API for valid HTML and well‐

formed XML documents

slide-3
SLIDE 3

 EXtensible Markup Language  XML is a markup language much like HTML  XML was designed to carry data, not to

display data

 XML tags are not predefined. You must define

your own tags

slide-4
SLIDE 4

 Whenever your web browser fetches a file (a

page, a picture, etc) from a web server

 HTTP is a Request/Response Protocol

slide-5
SLIDE 5

 AJAX = Asynchronous Javascript and XML  AJAX allows web pages to be updated

asynchronously by exchanging small amounts of data with the server behind the scenes.

 AJAX was made popular in 2005 by Google,

with Google Suggest.

slide-6
SLIDE 6

 AJAX is not new technology. AJAX is based

  • n internet standards:
  • XMLHttpRequest object (to exchange data

asynchronously with a server)

  • JavaScript/DOM (to display/interact with the

information)

  • CSS (to style the data)
  • XML (often used as the format for transferring

data)

slide-7
SLIDE 7
slide-8
SLIDE 8

 All modern browsers support the

XMLHttpRequest object

  • IE7+, Firefox, Chrome, Safari, and Opera
  • IE5 and IE6 use an ActiveXObject

 variable=new XMLHttpRequest();  variable=new ActiveXObject("Microsoft.XMLHTTP");

slide-9
SLIDE 9

var xmlhttp; if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else { // code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }

slide-10
SLIDE 10

 open(method,url,async)

  • xmlhttp.open("GET","ajax_info.php",true);

 send(string)

  • xmlhttp.send();
slide-11
SLIDE 11

 Sync / Async

slide-12
SLIDE 12

 Response by text

  • document.getElementById("myDiv").innerHTML=xml

http.responseText;

 Response by XML

  • xmlDoc=xmlhttp.responseXML;

txt=""; x=xmlDoc.getElementsByTagName("ARTIST"); for (i=0;i<x.length;i++) { txt=txt + x[i].childNodes[0].nodeValue + "<br>"; } document.getElementById("myDiv").innerHTML=txt;

slide-13
SLIDE 13

 XMLHttpRequest is a Javascript Object  Properties

  • readyState
  • responseText
  • responseXML
  • status
  • statusText

 Event Handler

  • onreadystatechange
slide-14
SLIDE 14

Value Definition Uninitialized Object contains no data 1 Loading Object is currently loading its data 2 Loaded Object has finished loading its data 3 Interactive User may interact with the object even though it’s not fully loaded 4 Complete Object has finished initializing

slide-15
SLIDE 15

Value Definition 200 OK 400 Bad Request 401 Unathorized 403 Forbidden 404 Not Found 500 Internal Server Error

slide-16
SLIDE 16

 abort()  getAllResponseHeaders()  getResponseHeader(“header name”)  open(“method”, “url”, async, [“user”,

“passwd”)

  • open(“GET”, “myfile.xml”, true)

 send(content)  setRequestHeader(“lable”, “value”)

slide-17
SLIDE 17
slide-18
SLIDE 18
slide-19
SLIDE 19
slide-20
SLIDE 20

 jqXHR object

  • Result of ajax request in jQuery
  • Properties

▪ readyState ▪ status ▪ statusText ▪ responseXML or responseText

  • methods

▪ setRequestHeader(name, value) ▪ getAllRequestHeaders() ▪ getResponseHeader() ▪ abort()

slide-21
SLIDE 21

 jQuery.ajax() $.ajax()

  • Sending asynchronous request
  • $.ajax( url, [settings])
  • Settings

▪ async:false [default ‐> true] ▪ beforeSend(jqXHR, settings) ▪ complete(jqXHR, textStatus)

▪ textStatus ‐> success, notmodified, error, timeout, abort, parsererror

▪ …

slide-22
SLIDE 22
slide-23
SLIDE 23

 type

  • GET, POST, PUT, DELETE

 dataType

  • Server response expected data type

▪ Text ▪ Script ▪ Html ▪ XML ▪ JSON

slide-24
SLIDE 24

 success

done

  • Callback function
  • Successful request
slide-25
SLIDE 25

 cache

  • Caching requested page in browser
  • false for script and true for others by default
slide-26
SLIDE 26

 data  async

slide-27
SLIDE 27

 $.load()  $.get()  $.post()  $.getJSON()  $.getScript()