Its good to restrict Page Access until The Page Completely Loaded.
Demo
HTML to be added to the Page
  1. <div id="spinner"></div>  

CSS on the Page
  1. #spinner {  
  2. positionfixed;  
  3. left: 0px;  
  4. top: 0px;  
  5. width100%;  
  6. height100%;  
  7. z-index9999;  
  8. backgroundurl(Image/preloader-w8-cycle-black.gif) 50% 50% no-repeat #808080;  
  9. }  

JavaScript On the Page
  1. <script type="text/javascript">  
  2. // <![CDATA[  
  3. $(window).load(function () { $("#spinner").fadeOut("slow"); })  
  4. // ]]></script>  

Complete HTML
  1. <html>  
  2. <head>  
  3. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>  
  4.  <style>  
  5.  
  6.         #spinner {  
  7.             position: fixed;  
  8.             left: 0px;  
  9.             top: 0px;  
  10.             width: 100%;  
  11.             height: 100%;  
  12.             z-index: 9999;  
  13.             *background: url(Image/preloader-w8-cycle-black.gif) 50% 50% no-repeat #808080;  
  14.         }  
  15.     </style>  
  16.     <!-- Preloader --><script type="text/javascript">// <![CDATA[  
  17.                       $(window).load(function () { $("#spinner").fadeOut("slow"); })  
  18.                       // ]]></script>  
  19. </head>  
  20. <body>  
  21. <div id="spinner"></div>  
  22. </body>  
  23. </html>  
Read More...

We can check if a page is loaded in Iframe or not using Javascript -- Why do we need this For me its Iframe APPS
So use the below code in the Iframe Page.Bingo you have the result.
  1. <script type="text/javascript">  
  2.     if (top == self)  
  3.         alert('Not in an iframe');  
  4.     else  
  5.         alert('In an iframe');  
  6. </script>  

Read More...


How do we write out Ajax Call usually
  1. $.ajax({  
  2.         type: 'POST',  
  3.         url: 'handler.ashx',  
  4.         contentType: 'application/json',  
  5.         dataType: 'json',  
  6.         processData: false,  
  7.         data: "{}",  
  8.         //Other code  
  9.         success: function (response) {  
  10.             // Update the UI here to reflect that the request was successful.  
  11.             var result = eval('(' + response.d + ')');  
  12.         },  
  13.         error: function (xmlHttpRequest, textStatus, errorThrown) {  
  14.             if (xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)  
  15.                 return true;  // it's not really an error ***Browser reload or exit  
  16.             else {  
  17.                 // Update the UI here to reflect that the request was unsuccessful  
  18.                 AJAXERROR('[function NAme]::' + xmlHttpRequest.responseText + '::[thrownerror]::' + errorThrown);  
  19.             }  
  20.         }  
  21.            
  22.     });  

Now lets take advantage of the jQuery.ajaxSetup() using this function you can predefine you common code in the Ajax call
Now i will take my normal code and use it in Ajax Setup
  1. $.ajaxSetup({  
  2.     type: 'POST',  
  3.         contentType: 'application/json',  
  4.         dataType: 'json',  
  5.         processData: false,  
  6.         data: "{}",  
  7.     error: function (xmlHttpRequest, textStatus, errorThrown) {  
  8.             if (xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)  
  9.                 return true;  // it's not really an error ***Browser reload or exit  
  10.             else {  
  11.                 // Update the UI here to reflect that the request was unsuccessful  
  12.         var fnName = arguments.callee.toString();  
  13.         fnName = fnName.substr('function '.length);  
  14.         fnName = fnName.substr(0, myName.indexOf('('));  
  15.                 alert('' + xmlHttpRequest.responseText + '::[thrownerror]::' + errorThrown);  
  16.             }  
  17.         }  
  18. });  

I use same error function to all so i have added it if you dont need it You can remove it or override it in the Ajax Call Later
As you can see i Have defined most of my Ajax options in the ajaxSetup.Now lets See how the Ajax Call reduces
  1. $.ajax({  
  2.            
  3.         url: 'handler.ashx',  
  4.         //Other code  
  5.         success: function (response) {  
  6.             // Update the UI here to reflect that the request was successful.  
  7.             var result = eval('(' + response.d + ')');  
  8.             //Do needed  
  9.         }  
  10.     });  

As you can see we have reducd almost 12 line of code
if we have 10 ajax functions then 12*10 = 120-12=108lines
the size of the file may not decrese by huge.but we can save the last few bytes of Javascript file.
Please provide your FeedBack will meet you in next Post
Read More...

Now when you are moving from SIT to Production
with a team like I am in trust me its a pain....
but i thought of what can i do to keep track of all this changes join hogwart's and learn magic
then i came across pinal's Article here and vola
Here is the query and visit pinal's site for any info
  1. SELECT name FROM sys.objects   
  2. WHERE type = 'P'   
  3. AND DATEDIFF(D,modify_date, GETDATE()) < 30  

some other types that may be helpful
Object type: AF = Aggregate function (CLR)
C = CHECK constraint
D = DEFAULT (constraint or stand-alone)
F = FOREIGN KEY constraint
FN = SQL scalar function
FS = Assembly (CLR) scalar-function
FT = Assembly (CLR) table-valued function
IF = SQL inline table-valued function
IT = Internal table
P = SQL Stored Procedure
PC = Assembly (CLR) stored-procedure
PG = Plan guide
PK = PRIMARY KEY constraint
R = Rule (old-style, stand-alone)
RF = Replication-filter-procedure
S = System base table
SN = Synonym
SO = Sequence object
SQ = Service queue
TA = Assembly (CLR) DML trigger
TF = SQL table-valued-function
TR = SQL DML trigger
TT = Table type
U = Table (user-defined)
UQ = UNIQUE constraint
V = View
X = Extended stored procedure

Read More...

HI All I have come across a requirement of
Dynamically loading the Javascript file On request.

Its pretty Simple Code
  1. <script type="text/javascript">  
  2.         function loadScript() {  
  3.             var script = document.createElement("script");  
  4.             script.type = "text/javascript";  
  5.             script.src = 'JScriptDynamic.js';  
  6.             document.body.appendChild(script);  
  7.         }  
  8.         window.onload = loadScript;  
  9. </script>  

  1. $(function(){  
  2. alert('FileLoaded');  
  3. })  

Now I am happy the file is loaded and i get alert saying
FileLoaded
now lets try to change the code little bit
  1. <script type="text/javascript">  
  2.         function loadScript() {  
  3.             var script = document.createElement("script");  
  4.             script.type = "text/javascript";  
  5.             script.src = 'JScriptDynamic.js';  
  6.             document.body.appendChild(script);  
  7.             alertload();  
  8.         }  
  9.         window.onload = loadScript;  
  10.     </script>  

  1. function alertload()  
  2. {  
  3.  alert(FileLoaded);  
  4. }  

boom we got a error @alertload();
Microsoft JScript runtime error: Object expected
Lets Dig...Why Does this happen? Ok:) no digging and ploughing its pretty simple logic
JScriptDynamic.js
not yet loaded
So what can we do now?
we know every DOM has a ONLOAD event so lets try this
  1. <script type="text/javascript">  
  2.         function loadScript() {  
  3.             var script = document.createElement("script");  
  4.             script.type = "text/javascript";  
  5.             script.src = 'JScriptDynamic.js';  
  6.             document.body.appendChild(script);  
  7.             script.onload = function () {  
  8.                 alertme();  
  9.             }  
  10.         }  
  11.         window.onload = loadScript;  
  12. </script>  

  1. function alertload()  
  2. {  
  3.  alert(FileLoaded);  
  4. }  


Yahoo..... Google chrome Showed the alert Now As most of the users still use IE,we need a test on IE
LET THE TEST BEGIN
its been 2 MIN !!!!!!!!!!!!!!!!!!!!!!!!!!!!! Where is my alert BOX?
don't worry IE Doesn't support onload for script element so we have a work around
  1. function loadScript( ) {  
  2.        var script = document.createElement("script");  
  3.        script.type = "text/javascript";  
  4.        script.src = "JScriptDynamic.js";  
  5.        document.body.appendChild(script);  
  6.        var browser = navigator.appName;  
  7.        if (browser = "Microsoft Internet Explorer") {  
  8.            ieLoadBugFix(script, function () {  
  9.                //alert('IE');  
  10.                alertload();  
  11.            });  
  12.        }  
  13.        else {  
  14.            script.onload = function () {  
  15.                //alert('nonIE');  
  16.                alertload()  
  17.            }  
  18.                }  
  19.    }  

  1. function ieLoadBugFix(scriptElement, callback) {  
  2.     if (scriptElement.readyState == 'loaded' || scriptElement.readyState == 'completed') {  
  3.         callback();  
  4.     } else {  
  5.         setTimeout(function () { ieLoadBugFix(scriptElement, callback); }, 100);  
  6.     }  
  7. }  

Now the Above code will work in all the Browsers. Happy Coding :)
Read More...

AJAX will end up hitting error method when any event in page cause page load or page unload.

OCCURS:

Why this occurs is due to the ajax call in the middle of fetching data from server and the page is forcing it to close connection

SOLUTION:

jQuery throws the error event when the user navigates away from the page either by refreshing, clicking a link, or changing the URL in the browser. You can detect these types of errors by by implementing an error handler for the ajax call, and inspecting the xmlHttpRequest object:


  1. if (xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)  
  2.                         return true;  // it's not really an error  
  3.                     else {  
  4.                         alert('[functionname]::' + xhr.responseText + '::[thrownerror]::' + thrownError);  
  5.                         OnError(xhr, thrownError);  
  6.                     }  
  7.   
  8. ///ERROR of ajax call  
  9.   
  10.  error: function (xmlHttpRequest, textStatus, errorThrown) {  
  11.                     if (xmlHttpRequest.readyState == 0 || xmlHttpRequest.status == 0)  
  12.                         return true;  // it's not really an error  
  13.                     else {  
  14.                         alert('[functionname]::' + xhr.responseText + '::[thrownerror]::' + thrownError);  
  15.                         OnError(xhr, thrownError);  
  16.                     }  
  17.                 }  

Alternative Approach:
you can check it by windows.unload event but its a function call more but more reliable
  1. var unloaded = false;  
  2. $.ajax(...) ...  
  3.  .error(function(jqXHR) {  
  4.     if (unloaded) return// Ignore errors caused by navigating away  
  5.     // Now, check for real errors ..  
  6. });  
  7. $(window).unload(function() {unloaded = true;});  
Read More...