Ajax XMLHttpRequest using javascript get results

31. December 2009

var xmlhttp

function showHint(str) {

    if (str.length == 0) {
        document.getElementById("txtHint").innerHTML = "";
        return;
    }
    xmlhttp = GetXmlHttpObject();
    if (xmlhttp == null) {
        alert("Your browser does not support XMLHTTP!");
        return;
    }
    var url = "CarService.asmx/GetAllCars";
    url = url + "?q=" + str;
    url = url + "&sid=" + Math.random();
    xmlhttp.onreadystatechange = stateChanged;
    xmlhttp.open("post", url, true);

    xmlhttp.setRequestHeader("Content-type", "text/xml");
    xmlhttp.setRequestHeader("Content-length", url.length);
    xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    xmlhttp.setRequestHeader("Connection", "close");


    xmlhttp.send(url);
   
}

function stateChanged() {
    if (xmlhttp.readyState == 4) {

      //  alert(xmlhttp.response);
        document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
        //  var yy = replace("a", eval('(' + xmlhttp.responseText + ')'));
        var xmlobject = (new DOMParser()).parseFromString(xmlhttp.responseText, "text/xml");

        var string = (new XMLSerializer()).serializeToString(xmlobject);
       // alert(string);


        var xmlobject = (new DOMParser()).parseFromString(string, "text/xml");
        // get the XML root item
        var root = xmlobject.getElementsByTagName('ArrayOfCar')[0];
        var ans = "";
        var items = root.getElementsByTagName("Car");
        for (var i = 0; i < items.length; i++) {
            // get one item after another
            var item = items[i];
            // now we have the item object, time to get the contents
            // get the name of the item
            var make = item.getElementsByTagName("Make")[0].firstChild.nodeValue;
            var model = item.getElementsByTagName("Model")[0].firstChild.nodeValue;
            // get the quantity
            var year = item.getElementsByTagName("Year")[0].firstChild.nodeValue;
            var door = item.getElementsByTagName("Doors")[0].firstChild.nodeValue;
            var color = item.getElementsByTagName("Colour")[0].firstChild.nodeValue;
            var price = item.getElementsByTagName("Price")[0].firstChild.nodeValue;
            //    alert("item #" + i + ": name=" + name + " quantity=" + quantity);
       
         ans +="<tr><td>"+make+"</td><td>"+model+"</td><td>"+year+"</td><td>"+door+"</td><td>"+color+"</td><td>"+price+"</td></tr>";

    }
    var table = '<table border="1" >';
       
        document.getElementById("Span1").innerHTML = table+ans+"<table>";
    
      //  var tt = xmlhttp.responseText;  //+ ')');
      //  alert("Node Value: " + tt.documentElement.childNodes[1].attributes.getNamedItem("model").nodeValue)
      //  document.getElementById("Span1").innerHTML += tt.ArrayOfCar;
     //   alert(response.d);
      //  var cars = (typeof xmlhttp.responseText) == 'string' ? eval('(' + xmlhttp.responseText + ')') : xmlhttp.responseText;
      //  alert(cars);
    }
}

function GetXmlHttpObject() {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject) {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, Javascript , ,

asp.net Menu and css Style

31. December 2009

<asp:Menu  ID="Menu1" Runat="server" DataSourceID="SamplesSiteMap"
             Orientation="Horizontal" BackColor="#6D90AC" DynamicHorizontalOffset="1" Font-Names="Verdana"
    Font-Size="12px" ForeColor="White" Height="25px" StaticSubMenuIndent="" BorderColor="Transparent"
    MaximumDynamicDisplayLevels="1" EnableTheming="True" Font-Bold="True" Font-Overline="False" Font-Strikeout="False"
    Font-Underline="False" ScrollDownText="" StaticPopOutImageUrl="~/members/template/images/menu/trileft.gif" SkipLinkText="" CssClass="toolbar" Width="919px"  OnMenuItemDataBound="Menu1_MenuDataBound" >
      <StaticMenuItemStyle HorizontalPadding="5px" BackColor="#6D90AC" BorderColor="#EAEAEA" Font-Bold="True"
       Font-Names="Verdana" Font-Size="12px" Height="31px" ItemSpacing="0px" VerticalPadding="0px" CssClass="menuitem" />
      <DynamicHoverStyle BackColor="#91AFC1" ForeColor="White" BorderColor="Transparent" Font-Bold="True"
      Font-Italic="False" Font-Names="Verdana" Font-Overline="False" Font-Size="12px" Font-Strikeout="False"
      Font-Underline="False" CssClass="dmenuitemover"/>
      <DynamicMenuStyle BackColor="#888888" BorderColor="#EAEAEA" CssClass="toolbar1" Font-Overline="False" />
      <StaticSelectedStyle BackColor="#587993" BorderColor="White" />
      <DynamicSelectedStyle BackColor="#587993" BorderColor="White" CssClass="selected" />
      <DynamicMenuItemStyle HorizontalPadding="5px"  BackColor="#6D90AC" BorderColor="#EAEAEA"
      Font-Bold="True" Font-Names="Verdana" Font-Size="12px" CssClass="dmenuitem" VerticalPadding="3px" />
      <StaticHoverStyle BackColor="#91AFC1" ForeColor="White" BorderColor="White" Font-Bold="True" Font-Names="Verdana"
      Font-Size="12px" CssClass="menuitemover" />
 
      <StaticMenuStyle BackColor="#6D90AC" BorderColor="#EAEAEA" Width="110px" Height="31px" HorizontalPadding="0px"
      VerticalPadding="0px" />
  </asp:Menu>

 

and css style

.toolbar
        {
           filter:progid:DXImageTransform.Microsoft.Shadow(color='#888888',
Direction=135, Strength=3);
       
        }
        .menuitem{
         border-left:0px #00ff00 solid;
         border-right:1px #00ff00 solid;
         border-bottom:1px #00ff00 solid;
         border-top:1px #00ff00 solid;        
        }
        .menuitemover{
            border-left:0px #00ff00 solid;
            border-right:1px #00ff00 solid;
            border-bottom:1px #00ff00 solid;
            border-top:1px #00ff00 solid;
         /*filter:"progid:DXImageTransform.Microsoft.GradientWipe(duration=.5, wipeStyle=1)"*/
        }
        .dmenuitem
        {
            text-align:left;
         border-left:0px #00ff00 solid;
         border-right:1px #00ff00 solid;
         border-bottom:1px #00ff00 solid;
         border-top:0px #00ff00 solid;
        }
        
        .selected{
         border-left:0px #00ff00 solid;
         border-right:1px #00ff00 solid;
         border-bottom:1px #00ff00 solid;
         border-top:0px #00ff00 solid;
        }
        .dmenuitemover{
          border-left:0px #00ff00 solid;
          border-right:1px #00ff00 solid;
          border-bottom:1px #00ff00 solid;
          border-top:0px #00ff00 solid;
        }
        .toolbar1
        {
         filter:progid:DXImageTransform.Microsoft.Shadow(color='#888888', Direction=157, Strength=2);
        }
        

     #idMainMenu  A,
     #Menu1  A:link,
     #Menu1  A:active,
     #Menu1  A:visited,
     #Menu1  A:hover,
     #Menu1  SPAN SPAN
{
 color:#ffffff;
 
 
 font-family: tahoma;
 font-size:larger;
 font-weight: bold;
 font-style: normal;
 line-height: normal;
 font-variant: normal;
 text-transform: none;
 text-decoration: none;
}


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, CSS ,

Ajax XmlHttpReest Script working fine on Firefox but not in IE 7

31. December 2009

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>

    

</head>
<body>
    <form name="form1" method="post" action="test.aspx" id="form1">
    <div id="news1">
    </div>
    </form>
</body>

<script type="text/javascript">

    function ahah(url, target)
    {
        document.getElementById(target).innerHTML = ' Fetching data...';
        if (window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
        }
        else if (window.ActiveXObject)
        {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        if (req != undefined)
        {
            req.onreadystatechange = function() { ahahDone(url, target); };
            req.open("GET", url, true);
            req.send("");
        }
    }

    function ahahDone(url, target)
    {
        if (req.readyState == 4)
        { // only if req is "loaded"
            if (req.status == 200)
            { // only if "OK"
                var s = req.responseText;
                s = s.slice(s.indexOf("<fo" + "rm"));
                s = s.replace("</body>", "");
                s = s.replace("</html>", "");
                s = s.replace(/<form/ig, "<formdisabled");
                document.getElementById(target).innerHTML = s;
            } else
            {
                document.getElementById(target).innerHTML = " AHAH Error:\n" + req.status + "\n" + req.statusText;
            }
        }
    }

    function load(name, div)
    {
        ahah(name, div);
        return false;
    }


    
    ahah('teste2.aspx', 'news1');//Comment this code at your side i have done this for testing


    //ahah('teste2.aspx', 'news1');//UnComment this code at your side i have done this for testin
    
//    GEvent.addListener(gmarkers[i], "click", function getStation()
//    {
//        ahah('teste2.aspx', 'news1');

//        return false;
//    });


</script>

</html>

 

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Hello
    </div>
    </form>
</body>
</html>

 

        if (req.readyState == 4)
        { // only if req is "loaded"
            if (req.status == 200)
            { // only if "OK"
                var s = req.responseText;
                s = s.slice(s.indexOf("<fo" + "rm"));
                s = s.replace("</body>", "");
                s = s.replace("</html>", "");
                s = s.replace(/<form/ig, "<formdisabled");
                document.getElementById(target).innerHTML = s;
            } else
            {
                document.getElementById(target).innerHTML = " AHAH Error:\n" + req.status + "\n" + req.statusText;
            }
        }


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

Ajax, ALL, asp.net, asp.net 4.0 , , ,

Ajax using XmlHttpRequest javascript

30. December 2009

 

Server ASP.NET Development Server/9.0.0.0
Date Thu, 31 Dec 2009 10:27:30 GMT
X-AspNet-Version 2.0.50727
Cache-Control private, max-age=0
Content-Type text/xml; charset=utf-8
Content-Length 359127
Connection Close
Request Headers
Host localhost:5346
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.4) Gecko/20091016 Firefox/3.5.4
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Content-Type application/x-www-form-urlencoded
Referer http://localhost:5346/WebSite4/





/***************************************************************************************/



Server ASP.NET Development Server/9.0.0.0
Date Thu, 31 Dec 2009 10:30:32 GMT
X-AspNet-Version 2.0.50727
Cache-Control private, max-age=0
Content-Type application/json; charset=utf-8
Content-Length 8818
Connection Close
X-lori-time-2 1262255432670
Request Headers
Host localhost:15943
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)
Accept application/json, text/javascript, */*
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 300
Connection keep-alive
Content-Type application/json; charset=utf-8
X-Requested-With XMLHttpRequest
Referer http://localhost:15943/presentationJSOn/WebUsersJSON.aspx
Content-Length 2
Cookie .DBANON=Rf1i0qjr-3L_3lr0YAie3kyDIxJ2MqPNCz3aqN-IlQHyL8GhvK8gzR2VcQxSLcaEZm1QAf9kOeXkf3_snjyopziDBy9yAZWlYGp2l5ZFVwg1; ASP.NET_SessionId=z43jgu45rewsqxyjgj51i445; .AUTHCOOKIE=EFCDFF2762B619C41028425FFA00D2B6D15ECAD39F2122D869342EC3D351623DAB4A727DE1715E438A4B607E8E481B390712D74E5F45B61F5CBF6D7D4ADEC45D
X-lori-time-1 1262255432633






/***************************************************************************************/

var xmlhttp

function showHint(str) {
if (str.length == 0) {
document.getElementById("txtHint").innerHTML = "";
return;
}
xmlhttp = GetXmlHttpObject();
if (xmlhttp == null) {
alert("Your browser does not support XMLHTTP!");
return;
}
var url = "WebService.asmx/Serialize";
url = url + "?q=" + str;
url = url + "&sid=" + Math.random();
xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Content-type", "application/json; charset=utf-8");
xmlhttp.setRequestHeader("Content-length", url.length);
xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xmlhttp.setRequestHeader("Connection", "close");



xmlhttp.send(null);
}

function stateChanged() {
if (xmlhttp.readyState == 4) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
var t = xmlhttp.responseText;
alert(t.length);



}
}

function GetXmlHttpObject() {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject) {
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.Script.Services;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

////System.Net.WebClient Client = new WebClient();
////Stream strm = Client.OpenRead("http://www.google.com");
////StreamReader sr = new StreamReader(strm);
////string line;
////do
////{
//// line = sr.ReadLine();
//// listbox1.Items.Add(line);
////}
////while (line != null);
////strm.Close();



}
[WebMethod, ScriptMethod]
public List<String> GetCustomerNamesS()
{
List<String> customerList = new List<String>();
customerList.Add("John");
customerList.Add("Jacob");
customerList.Add("Mary");
customerList.Add("Peter");
customerList.Add("Darren");
return customerList;





}

[WebMethod]
public string Serialize()
{
JavaScriptSerializer ser = new JavaScriptSerializer();

List<JavaScriptConverter> converters = new List<JavaScriptConverter>();

List<String> customerList = new List<String>();
customerList.Add("John");
customerList.Add("Jacob");
customerList.Add("Mary");
customerList.Add("Peter");
customerList.Add("Darren");


return ser.Serialize(customerList);
}




}


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL , , , ,

reasons for session loss

30. December 2009

There are a lot of reasons for session loss. To name a few,

1-  Application Pool is recycled. - We will know this looking at the system logs
2-  IIS/worker process is restarted. - System logs will tell this as well
3-  Application Domain is restarted. - We need to monitor for application restarts for the ASP.NET counter in perfmon to check this. Few reasons for application restarts include
4- Bin folder of the application is touched by some application
5- Web.config or the machine.config is touched
6- Global.asax file is touched
7- Antivirus is running
8- Something in the code is causing session loss, it can be anything. You will need to look into the code to have a fix on this.


Author: Aamir Hasan     औथोर: आमिर हसन       أثر أمير حسن .

ALL, asp.net, asp.net 4.0 ,



User Name: Guest

Your Ip: 38.107.191.93
Time: