Showing posts with label Ajax. Show all posts
Showing posts with label Ajax. Show all posts

Monday, March 13, 2017

Create an Animation Using Ajax

ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient, more interactive and highly-personalized Web experiences that work across all the most popular browsers.

Ajax is not a programming language or a tool, but a concept. Ajax is a client-side script that communicates to and from a server/database without the need for a postback or a complete page refresh.

Ajax is “the method of exchanging data with a server, and updating parts of a web page - without reloading the entire page.

Let's have a look at Ajax,

Animation.aspx
  1. <%@ Page Language="C#" %>  
  2.     <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>  
  3.         <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>  
  4.             <%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %>  
  5.                 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  6.                 <html xmlns="http://www.w3.org/1999/xhtml">  
  7.   
  8.                 <head id="Head1" runat="server">  
  9.                     <title>Control Toolkit</title>  
  10.                     <style type="text/css">  
  11.                     .panelClass {  
  12.                         background-color: lime;  
  13.                         width: 300px;  
  14.                     }  
  15.                     </style>  
  16.                     <script type="text/javascript">  
  17.                     function pageLoad()  
  18.                     {  
  19.                         var ae = $find("ae");  
  20.                         var animation = '{"AnimationName":"Sequence","AnimationChildren":[{"AnimationName":"EnableAction","Enabled":"false","AnimationChildren":[]},{"AnimationName":"Parallel","AnimationChildren":[{"AnimationName":"FadeOut","Duration":"1.5","Fps":"24","AnimationTarget":"Panel1","AnimationChildren":[]},{"AnimationName":"Resize","Width":"1000","Height":"150","Unit":"px","AnimationTarget":"Panel1","AnimationChildren":[]}]}]}';  
  21.                         ae.set_OnClick(animation);  
  22.                         ae.OnClick();  
  23.                     }  
  24.                     </script>  
  25.                 </head>  
  26.   
  27.                 <body>  
  28.                     <form id="form1" runat="server">  
  29.                         <asp:ScriptManager ID="ae" runat="server"> </asp:ScriptManager>  
  30.                         <div>  
  31.                             <asp:Panel ID="Panel1" CssClass="panelClass" runat="server"> ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient, more interactive and highly-personalized Web experiences that work across all the most popular browsers.  
  32.                                 <br /> ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient, more interactive and highly-personalized Web experiences that work across all the most popular browsers.  
  33.                                 <br /> ASP.NET AJAX is a free framework for quickly creating a new generation of more efficient, more interactive and highly-personalized Web experiences that work across all the most popular browsers.  
  34.                                 <br /> </asp:Panel>  
  35.                             <input type="button" id="Button1" runat="server" value="Launch Animation" />  
  36.                             <cc1:AnimationExtender ID="AnimationExtender2" runat="server" TargetControlID="Button1"> </cc1:AnimationExtender>  
  37.                         </div>  
  38.                     </form>  
  39.                 </body>  
  40.   
  41.             </html>  
Guys, Please download Ajax Control Toolkit if you don't have already. 

Keep exploring. If you have any doubt, please feel free to ask me.

Saturday, January 14, 2017

JSON (JavaScript Object Notation) HTTP Request by Ajax to Show Data on Webpage

First,We create one .Txt file which contains names of different countries.

Country.txt File: 
  1. [  
  2.     {  
  3.         "display""India",  
  4.     },   
  5.     {  
  6.         "display""China",  
  7.     },   
  8.     {  
  9.         "display""USA",  
  10.     },   
  11.     {  
  12.         "display""UK",  
  13.     },   
  14.     {  
  15.         "display""Canada",  
  16.     },   
  17.     {  
  18.         "display""Japan",  
  19.     },   
  20.     {  
  21.         "display""Russia",  
  22.     },   
  23. ]  
In the second step, Reads the data from file and display it to the webpage. Use XMLHttpRequest to read the text file, and use fetchData () to display the array.

JsonHttpXmlReqbyAjax.html  
  1. <!DOCTYPE html>  
  2. <html>  
  3. <body>  
  4. <div id="maindiv"></div>  
  5. <script>  
  6. var xmlhttp = new XMLHttpRequest();  
  7. var url = "Country.txt";  
  8. xmlhttp.onreadystatechange = function()  
  9. {  
  10.    if (xmlhttp.readyState == 4 && xmlhttp.status == 200)  
  11.    {  
  12.          var myarray = JSON.parse(xmlhttp.responseText);  
  13.          fetchData(myarray);  
  14.    }  
  15. }  
  16. xmlhttp.open("GET", url, true);  
  17. xmlhttp.send();  
  18. function fetchData(arr)  
  19. {  
  20.          var out = "";  
  21.          var i;  
  22.           for(i = 0; i < arr.length; i++)  
  23.          {  
  24.                out += arr[i].display + '<br>';  
  25.          }  
  26.          document.getElementById("maindiv").innerHTML = out;  
  27. }  
  28. </script>  
  29. </body>  
  30. </html>  
After completing all these steps, you will get following output.

India
China
USA
UK
Canada
Japan
Russia 
Enjoy Coding...!!!