Programming techniques

about every things that i''m learning and want learn to other people

Programming techniques

about every things that i''m learning and want learn to other people

XMLHttpRequest , XML DOM

The XMLHttpRequest Object

The XMLHttpRequest object is used to exchange data with a server behind the scenes.

The XMLHttpRequest object is a developer's dream, because you can:

  • ·        Update a web page without reloading the page
  • ·        Request data from a server after the page has loaded
  • ·        Receive data from a server after the page has loaded
  • ·        Send data to a server in the background  

·         

Syntax for creating an XMLHttpRequest object:

xmlhttp=new XMLHttpRequest(); 

 

Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object:

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 

 

 

An XML parser converts an XML document into an XML DOM object 

  

Parse an XML Document 

if (window.XMLHttpRequest)

            {// code for IE7+, Firefox, Chrome, Opera, Safari

                xmlhttp = new XMLHttpRequest();

            }

            else

            {// code for IE6, IE5

                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

            }

            xmlhttp.open("GET", "books.xml", false);

            xmlhttp.send();

            xmlDoc = xmlhttp.responseXML;

 

 

Parse an XML String  

txt = "<bookstore><book>";

            txt = txt + "<title>Everyday Italian</title>";

            txt = txt + "<author>Giada De Laurentiis</author>";

            txt = txt + "<year>2005</year>";

            txt = txt + "</book></bookstore>";

            if (window.DOMParser)

            {

                parser = new DOMParser();

                xmlDoc = parser.parseFromString(txt, "text/xml");

            }

            else // Internet Explorer

            {

                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");

                xmlDoc.async = false;

                xmlDoc.loadXML(txt);

            }

 

The XML DOM

The XML DOM defines a standard way for accessing and manipulating XML documents. 

 

The XML DOM views an XML document as a tree-structure 

 

The HTML DOM

The HTML DOM defines a standard way for accessing and manipulating HTML documents.

All HTML elements can be accessed through the HTML DOM 

 

نظرات 0 + ارسال نظر
برای نمایش آواتار خود در این وبلاگ در سایت Gravatar.com ثبت نام کنید. (راهنما)
ایمیل شما بعد از ثبت نمایش داده نخواهد شد