Tuesday 9 February 2016

Front End Web Development



In this track, you’ll learn how to build beautiful, interactive websites by learning the fundamentals of HTML, CSS, and JavaScript — three common coding languages on which all modern websites are built. This is a useful and lucrative skill to acquire as it used by nearly every single business in the world that needs a website to communicate to its customers. By the end of this track, you’ll have all the skills required to build your own websites or even start a career with one of the thousands of companies that have a website.

Developers Best Practices Tutorial

This small tutorial is based on my past 16+ years of experience in software development industry. I have gone through different stages in my career starting from trainee software developer till senior management.
I do not want to keep my learnings to myself, so I had written a small tutorial few years ago, and after getting lot of motivation from my dear readers, I thought of revising it and adding few more learnings which may benefit many other software engineers and developers working in this lovely industry.
I'm not going to dictate any of the points, but all the practices listed here contributed a lot in my software development career, so if you think they make some sense for you then try to adopt few. If you have any +/- comments, kindly feel free to write me 

Audience

If you are working for software industry as a software engineer or a software developer, then I'm sure you are going to enjoy this tutorial. Try to relate the facts mentioned in the tutorial with your day-2-day life and find so many hidden facts, which are very obvious but we never gave our serious attention to them.

Prerequisites

Before writing all the practices mentioned in this small tutorial, I have made an assumption that you are working as a software professional and you understand basic software terminologies and atmosphere around a software professional.

AJAX - Browser Support

All the available browsers cannot support AJAX. Here is a list of major browsers, that support AJAX.
  • Mozilla Firefox 1.0 and above.
  • Netscape version 7.1 and above.
  • Apple Safari 1.2 and above.
  • Microsoft Internet Explorer 5 and above.
  • Konqueror.
  • Opera 7.6 and above.
When you write your next application, do consider the browsers that do not support AJAX.
NOTE: When we say that a browser does not support AJAX, it simply means that the browser does not support creation of Javascript object XMLHttpRequest object.

Writing Browser Specific Code

The Simplest way to make your source code compatible with a browser is to use try...catch blocks in your JavaScript.
<html>
<body>
   <script language="javascript" type="text/javascript">
   <!-- 
   //Browser Support Code
   function ajaxFunction(){
      var ajaxRequest;  // The variable that makes Ajax possible!

      try{
         // Opera 8.0+, Firefox, Safari 
         ajaxRequest = new XMLHttpRequest();
      }catch (e){

         // Internet Explorer Browsers
         try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
         }catch (e) {
            try{
               ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){

               // Something went wrong
               alert("Your browser broke!");
               return false;
            }
         }
      }
   }
   //-->
   </script>
   
   <form name='myForm'>
      Name: <input type='text' name='username' /> <br />
      Time: <input type='text' name='time' />
   </form>
   
</body>
</html>
In the above JavaScript code, we try three times to make our XMLHttpRequest object. Our first attempt:
  • ajaxRequest = new XMLHttpRequest();
It is for Opera 8.0+, Firefox, and Safari browsers. If it fails, we try two more times to make the correct object for an Internet Explorer browser with:
  • ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  • ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
If it doesn't work, then we can use a very outdated browser that doesn't support XMLHttpRequest, which also means it doesn't support Ajax.
Most likely though, our variable ajaxRequest will now be set to whatever XMLHttpRequest standard the browser uses and we can start sending data to the server. The step-wise AJAX workflow is explained in the next chapter.

Thursday 4 February 2016

AJAX - Browser Support

All the available browsers cannot support AJAX. Here is a list of major browsers, that support AJAX.
  • Mozilla Firefox 1.0 and above.
  • Netscape version 7.1 and above.
  • Apple Safari 1.2 and above.
  • Microsoft Internet Explorer 5 and above.
  • Konqueror.
  • Opera 7.6 and above.
When you write your next application, do consider the browsers that do not support AJAX.
NOTE: When we say that a browser does not support AJAX, it simply means that the browser does not support creation of Javascript object XMLHttpRequest object.

Writing Browser Specific Code

The Simplest way to make your source code compatible with a browser is to use try...catch blocks in your JavaScript.

<html>
<body>
   <script language="javascript" type="text/javascript">
   <!-- 
   //Browser Support Code
   function ajaxFunction(){
      var ajaxRequest;  // The variable that makes Ajax possible!

      try{
         // Opera 8.0+, Firefox, Safari 
         ajaxRequest = new XMLHttpRequest();
      }catch (e){

         // Internet Explorer Browsers
         try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
         }catch (e) {
            try{
               ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (e){

               // Something went wrong
               alert("Your browser broke!");
               return false;
            }
         }
      }
   }
   //-->
   </script>
   
   <form name='myForm'>
      Name: <input type='text' name='username' /> <br />
      Time: <input type='text' name='time' />
   </form>
   
</body>
</html>
 
 
In the above JavaScript code, we try three times to make our XMLHttpRequest object. Our first attempt:
  • ajaxRequest = new XMLHttpRequest();
It is for Opera 8.0+, Firefox, and Safari browsers. If it fails, we try two more times to make the correct object for an Internet Explorer browser with:
  • ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
  • ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
If it doesn't work, then we can use a very outdated browser that doesn't support XMLHttpRequest, which also means it doesn't support Ajax.
Most likely though, our variable ajaxRequest will now be set to whatever XMLHttpRequest standard the browser uses and we can start sending data to the server. The step-wise AJAX workflow is explained in the next chapter
 

AJAX - Technologies

AJAX cannot work independently. It is used in combination with other technologies to create interactive webpages.

JavaScript

  • Loosely typed scripting language.
  • JavaScript function is called when an event occurs in a page.
  • Glue for the whole AJAX operation.

DOM

  • API for accessing and manipulating structured documents.
  • Represents the structure of XML and HTML documents.

CSS

  • Allows for a clear separation of the presentation style from the content and may be changed programmatically by JavaScript.

XMLHttpRequest

  • JavaScript object that performs asynchronous interaction with the server.

AJAX Tutorial

AJAX, is a web development technique for creating interactive web applications.
If you know JavaScript, HTML, CSS, and XML, then you need to spend just one hour to start with AJAX.

Audience

This tutorial will be useful for web developers who want learn how to create interactive webpages as well as improve their speed and usability using AJAX.

Prerequisites

It is highly recommended that you are familiar with HTML and JavaScript before attempting this tutorial.
  • AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS, and Java Script.
  • Ajax uses XHTML for content, CSS for presentation, along with Document Object Model and JavaScript for dynamic content display.
  • Conventional web applications transmit information to and from the server using synchronous requests. It means you fill out a form, hit submit, and get directed to a new page with new information from the server.
  • With AJAX, when you hit submit, JavaScript will make a request to the server, interpret the results, and update the current screen. In the purest sense, the user would never know that anything was even transmitted to the server.
  • XML is commonly used as the format for receiving server data, although any format, including plain text, can be used.
  • AJAX is a web browser technology independent of web server software.
  • A user can continue to use the application while the client program requests information from the server in the background.
  • Intuitive and natural user interaction. Clicking is not required, mouse movement is a sufficient event trigger.
  • Data-driven as opposed to page-driven.

Rich Internet Application Technology

AJAX is the most viable Rich Internet Application (RIA) technology so far. It is getting tremendous industry momentum and several tool kit and frameworks are emerging. But at the same time, AJAX has browser incompatibility and it is supported by JavaScript, which is hard to maintain and debug.

AJAX is Based on Open Standards

AJAX is based on the following open standards:
  • Browser-based presentation using HTML and Cascading Style Sheets (CSS).
  • Data is stored in XML format and fetched from the server.
  • Behind-the-scenes data fetches using XMLHttpRequest objects in the browser.
  • JavaScript to make everything happen.