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

?GET or POST

GET or POST?

GET is simpler and faster than POST, and can be used in most cases.

However, always use POST requests when:

  • A cached file is not an option (update a file or database on the server)
  • Sending a large amount of data to the server (POST has no size limitations)
  • Sending user input (which can contain unknown characters), POST is more robust and secure than GET

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 

 

Cross-browser vs. Multi-browser

 Cross-browser

Cross-browser refers to the ability of a website, web application, HTML construct  

or client-side script to function in environments that provide its required features and to bow out or degrade gracefully when features are absent or lacking.

 Cross-browser vs. Multi-browser

With regard to scripts, which is the most common usage, the term cross-browser is often confused with multi-browser (see jQuery). Multi-browser scripts can only be expected to work in environments where they have been demonstrated to work (due to assumptions based on observing a subset of browsers). Most publicly available libraries and frameworks are multi-browser scripts and list the environments (typically popular browsers in use at the time and in their default configurations) where they can be expected to work.