<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>YourSearchBuddy &#187; Ajax</title>
	<atom:link href="http://www.yoursearchbuddy.com/tag/ajax/feed" rel="self" type="application/rss+xml" />
	<link>http://www.yoursearchbuddy.com</link>
	<description>your search ends here</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:47:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Ajax POST method, using xmlhttprequest</title>
		<link>http://www.yoursearchbuddy.com/ajax-xmlhttpequest</link>
		<comments>http://www.yoursearchbuddy.com/ajax-xmlhttpequest#comments</comments>
		<pubDate>Tue, 07 Jun 2011 04:08:46 +0000</pubDate>
		<dc:creator>lokeshlal</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[TipnTricks]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[method]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[xmlhttprequest]]></category>

		<guid isPermaLink="false">http://www.yoursearchbuddy.com/?p=5200</guid>
		<description><![CDATA[To post data using ajax xmlhttp protocol. var request; function createAjax(url,callbackfunction,parameters,method) { try { request = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e1) { try { request = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e2) {... <a class="meta-more" href="http://www.yoursearchbuddy.com/ajax-xmlhttpequest">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>To post data using ajax xmlhttp protocol.</p>
<pre>
        var request;
        function createAjax(url,callbackfunction,parameters,method)
        {
            try
            {
                request = new ActiveXObject("Microsoft.XMLHTTP");

            }
            catch(e1)
            {
                try
                {
                    request = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e2)
                {
                    try
                    {
                        request = new XMLHttpRequest();
                    }
                    catch(e3)
                    {
                        alert("Error initializing XmlHttp object!!!");
                    }
                }
            }

            request.open(method,url,true)
            request.onreadystatechange = callbackfunction;
            if(method == "POST")
            {
                request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                request.setRequestHeader("Content-length", parameters.length);
                request.setRequestHeader("Connection", "close");
            }
            request.send(parameters);
        }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.yoursearchbuddy.com/ajax-xmlhttpequest/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax with .NET using XMLHttpRequest Object</title>
		<link>http://www.yoursearchbuddy.com/ajax-net-xmlhttprequest-object</link>
		<comments>http://www.yoursearchbuddy.com/ajax-net-xmlhttprequest-object#comments</comments>
		<pubDate>Fri, 29 Apr 2011 12:36:22 +0000</pubDate>
		<dc:creator>lokeshlal</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[xmlhttpobject]]></category>

		<guid isPermaLink="false">http://www.yoursearchbuddy.com/?p=4491</guid>
		<description><![CDATA[How to use Ajax with .Net using basic JavaScript method (xmlhttprequest object) Setup a client side method(Javascript) that will initiate the process and a method that will handle the result... <a class="meta-more" href="http://www.yoursearchbuddy.com/ajax-net-xmlhttprequest-object">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>How to use Ajax with .Net using basic JavaScript method (xmlhttprequest object)</p>
<p>Setup a client side method(Javascript) that will initiate the process and a method that will handle the result return by the server.</p>
<pre>
   var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }
     }
   }

   if (!request)
     alert("Error initializing XMLHttpRequest!");

   function createRequest() {
     var information = document.getElementById("information").value;
     var url = "/serverhandler.ashx?information=" + escape(information);
     request.open("GET", url, true);
     request.onreadystatechange = updatePage;
     request.send(null);
   }

   function updatePage() {
     alert("Server is done!"); // process the request
if(request.readystate == 4)
{ var resopnse = request.responseText; document.write(response);}
   }
</pre>
<p>Now create a server side method that will handle the request and send back the result to the client.<br />
We can go for a HttpHandler or a web page that will handle the request.<br />
if you are not aware of Httphandler than its not a problem,<br />
 you are not the only one. they appear very early in the page life cycle so by using them<br />
 we can increase the performance.</p>
<p>creating a HttpHanlder (serverhandler.ashx file)</p>
<pre>

using System;
using System.Web;
using System.Web.SessionState;
public class result : IHttpHandler,IRequiresSessionState // IRequiresSessionState is used so that we can use the session variables in our handler
{
    public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
string information = context.Request.QueryString["information"].ToString();
context.Response.Write("hello" + information);}
    public bool IsReusable {        get {            return true;        }    }}
 </pre>
<p>we can also use a page serverhandler.aspx, to do so delete every thing in the .aspx page except<br />
 the register tag that tells about the code behind of the page and then in the code behind write<br />
 the same code as in the processrequest method of a HttpHandler above.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yoursearchbuddy.com/ajax-net-xmlhttprequest-object/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Ajax Javascript Problem</title>
		<link>http://www.yoursearchbuddy.com/aspnet-ajax-javascript-problem</link>
		<comments>http://www.yoursearchbuddy.com/aspnet-ajax-javascript-problem#comments</comments>
		<pubDate>Fri, 28 Jan 2011 16:31:40 +0000</pubDate>
		<dc:creator>lokeshlal</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[TipnTricks]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Problem]]></category>

		<guid isPermaLink="false">http://www.yoursearchbuddy.com/?p=2744</guid>
		<description><![CDATA[Last week I was working on a control, where i was required to load a control using Ajax ModalExtendender Pop up control and then there are various links on the... <a class="meta-more" href="http://www.yoursearchbuddy.com/aspnet-ajax-javascript-problem">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last week I was working on a control, where i was required to load a control using Ajax ModalExtendender Pop up control and then there are various links on the page. on click of each link, first I have to do some actions on client side and then post back the page.</p>
<p>But somehow, every time i was trying to do the same, the JavaScript code was not working.</p>
<p>The reason for this was that my JavaScript function (it was a very small function which actually requires some server control ids) was on my pop up only. which i was loading using ajax. so when we load some content using Ajax, it will be treated as pure html and not as javascript, even if you put the script tag in the response.</p>
<p>So to fix this, instead of calling a js function, i just wrote a single line of JavaScript on click event it self.</p>
<p>Hope this info will be of some help.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.yoursearchbuddy.com/aspnet-ajax-javascript-problem/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using HttpModule to Handle Ajax Calls</title>
		<link>http://www.yoursearchbuddy.com/httpmodule-handle-ajax-calls</link>
		<comments>http://www.yoursearchbuddy.com/httpmodule-handle-ajax-calls#comments</comments>
		<pubDate>Mon, 28 Jun 2010 13:55:53 +0000</pubDate>
		<dc:creator>lokeshlal</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Httpmodule]]></category>

		<guid isPermaLink="false">http://yoursearchbuddy.com/?p=624</guid>
		<description><![CDATA[Download Example Introduction This is an article about how we can use httpmodule to handle an Ajax request. I have added a new function to directly load the HTML container... <a class="meta-more" href="http://www.yoursearchbuddy.com/httpmodule-handle-ajax-calls">Read more <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p><span></p>
<ul>
<li>
<a href="http://yoursearchbuddy.com/Code_Files/SomeDummyHttpModuleExample.zip">Download Example</a>
</li>
</ul>
<h2>Introduction</h2>
<p>This is an article about how we can use <code>httpmodule </code>to handle an Ajax request. </p>
<p>I have added a new function to directly load the HTML container and HTML attributes so that we can attach with HTML elements. I added cross domain Ajax calls fucntionality.</p>
<ul>
<li><code>onAjaxClick</code> </li>
<li><code>onAjaxClickContainer</code> </li>
<li><code>onAjaxClickCrossDomain</code> </li>
<li><code>xmlHttpRequestObject1.createAjax();</code> </li>
<li><code>xmlHttpRequestObject1.createAjaxContainer();</code> </li>
<li><code>xmlHttpRequestObject1.createAjaxCrossDomain();</code> </li>
</ul>
<h2>Background</h2>
<p>This is the first sample that I have created using HttpModule. So I thought of using HttpModule with a bit of reflection and AJAX and creating a very basic AJAX Framework. </p>
<p>Now I am using ajaxScript in a resource file to access JavaScript in the handler. </p>
<h2>The Code</h2>
<p>Create an <code>HttpModule</code> class: </p>
<pre>namespace SomeDummyHttpModuleExample
{
    public class getAssemblyInformation
    {
        public void setAssemblyInformation(HttpApplication context,
            System.Reflection.Assembly a)
        {
            context.Session[&quot;set_assmbly_information&quot;] = a.FullName;
        }
    }

    public class HttpModuleExample : IHttpModule
    {

        public String ModuleName
        {
            get { return &quot;HttpModuleExample&quot;; }
        }

        public void Dispose()
        { }

        public void Init(HttpApplication context)
        {
            //context.PreRequestHandlerExecute += new EventHandler(context_BeginRequest);
            //context.BeginRequest += new EventHandler(context_BeginRequest);
            context.EndRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            //if (((HttpApplication)sender).Request.Url.ToString().IndexOf(
            //&quot;smidxop=&quot;) == -1)

            string s123 = ((HttpApplication)sender).Response.ContentType;
            //((HttpApplication)sender).
            if (((HttpApplication)sender).Request.Url.ToString().IndexOf(
                &quot;SomeDummyHttpModuleExample&quot;) == -1)
            {
                string scriptFromRes =
                    SomeDummyHttpModuleExample.Properties.Resources.ajaxScript.ToString();
                ((HttpApplication)sender).Context.Response.Write(scriptFromRes);
            }
            else
            {
                try
                {
                    string s = ((HttpApplication)sender).Request.Url.ToString();
                    string[] values = s.Split('?');
                    if (values.Length &gt; 2)
                    {
						if (values[2].ToString() ==
                                                           &quot;_c_d_caLL_f_cLiEnT&quot;)
                        {
                            System.Net.HttpWebRequest webReq = (
                                System.Net.HttpWebRequest)System.Net.WebRequest.Create(
                                values[1].ToString());
                            webReq.KeepAlive = false;

                            System.Net.HttpWebResponse webresponse;
                            webresponse = (System.Net.HttpWebResponse)webReq.GetResponse();

                            Encoding enc = System.Text.Encoding.GetEncoding(1252);
                            System.IO.StreamReader loResponseStream = new
                              System.IO.StreamReader(webresponse.GetResponseStream(), enc);

                            string Response = loResponseStream.ReadToEnd();

                            try
                            {
                                ((HttpApplication)sender).Response.Write(
                                    HttpUtility.HtmlDecode(Response));
                                ((HttpApplication)sender).Response.Flush();
                                ((HttpApplication)sender).Response.Close(); //End();
                            }
                            catch (Exception ex)
                            { }

                        }
                        else
                        {
                            //'SomeDummyHttpModuleExample?' + namespace + '?' +
                            //method + '?' + parameters
                            AppDomain appDom = AppDomain.CurrentDomain;
                            foreach (Assembly aaa in appDom.GetAssemblies())
                            {
                                if (aaa.GlobalAssemblyCache == true)
                                    continue;
                                foreach (Type tys in aaa.GetTypes())
                                {
                                    if (tys.FullName.ToLower().Contains(
                                        values[1].ToLower().ToString()) &amp;&amp;
                                        tys.IsSubclassOf(typeof(BasePage)) == true)
                                    {
                                        foreach (MethodInfo mmm in tys.GetMethods())
                                        {
                                            if (mmm.Name == values[2].ToString())
                                            {
                                                string[] parameters;
                                                parameters = new string[] { };
                                                if (values[3].Trim().Length != 0)
                                                    parameters =
                                                        values[3].Trim().Split(',');

                                                object returnValue;
                                                object[] paramArray = new object[] { };
                                                if (parameters.Length == 0)
                                                    returnValue = mmm.Invoke(null, null);
                                                else
                                                {
                                                    paramArray =
                                                        new object[parameters.Length];
                                                    int g = 0;
                                                    foreach (string ss in parameters)
                                                    {
                                                        paramArray[g] = (object)ss;
                                                        g++;
                                                    }
                                                    returnValue = mmm.Invoke(null,
                                                        paramArray);
                                                }
                                                try
                                                {
                                                    ((
                                                    HttpApplication)sender).Response.Write(
                                                        Convert.ToString(returnValue));
                                                    ((HttpApplication)sender).Response.Flush();
                                                    //End();
                                                    ((HttpApplication)sender).Response.Close();
                                                }
                                                catch (Exception ex)
                                                { }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ((HttpApplication)sender).Context.Response.Write(
                       ex.Message + &quot; -- &quot; + ex.StackTrace);
                    ((HttpApplication)sender).Context.Response.Flush();
                    ((HttpApplication)sender).Context.Response.Close();
                }
            }
        }
    }
}</pre>
<p>Create a base class for Web pages: </p>
<pre>using System.Web;
using System.Web.UI;

namespace SomeDummyHttpModuleExample
{
    public class BasePage : Page
    {
        public BasePage(Type t) { }
        public BasePage() { }
    }
}</pre>
<p>You can get rid of the base class if you want, just remove the check for the base class in the <code>httpmodule </code>class. </p>
<p>Add a reference of this DLL into your ASP.NET project. Use the following syntax to create an Ajax request. </p>
<pre>var xmlHttpRequestObject1 =
	new xmlHttpRequestObject('callbackpage','dummyMethod','','handlecal');
//dummyMethod method should be a static method declared in the callbackpage class.

var xmlHttpRequestObject1 =
    //or can directly pass the function reference handlecal
	new xmlHttpRequestObject('callbackpage','dummyMethod','',handlecal);</pre>
<p><code>dummyMethod </code>can be a parameterised or parameterless method. If it is parameterised, then we have to pass the parameter in a comma separated string. e.g. </p>
<pre>var xmlHttpRequestObject1 = new xmlHttpRequestObject
	('callbackpage','dummyMethod','one parameter only','handlecal');

var xmlHttpRequestObject1 = new xmlHttpRequestObject
   ('callbackpage','dummyMethod','one parameter only, second parameter','handlecal');

xmlHttpRequestObject(Class Complete Path,Static Method Name,
	Comma Separated Parameter List,Call back javascript function); 

xmlHttpRequestObject1.createAjax(); //To initiate request

function handlecal(resp) //call back handler with response â€˜respâ€™
 {
     alert(resp);
 }

xmlHttpRequestObject1.createAjaxContainer(); //To initiate request to populate container</pre>
<p>You can also pass the function reference as </p>
<pre>var xmlHttpRequestObject1 = new xmlHttpRequestObject
	('callbackpage','dummyMethod','one parameter only',handlecal); //Without quotes</pre>
<p>Initiating an Ajax request to populate a container </p>
<pre>var xmlHttpRequestObject1 = new xmlHttpRequestObject('_Default','getServerTime',
    '','time');//time is Id of HTML container
xmlHttpRequestObject1.createAjaxContainer(); //createAjaxContainer function to
                                             //populate html element</pre>
<p>Adding an HTML attribute to an HTML element to intiate an Ajax request on onclick function </p>
<pre>onAjaxClick=&quot;_Default,getFirstNameLastName,Lokesh$Lal,handlecal2&quot;
//Parameters seperated by $(dollar sign) in attribute.
//handlecal2 is name of function in javascript that will recieve response.</pre>
<pre>onAjaxClickContainer=&quot;_Default,getFirstNameLastName,Lokesh$Lal,time&quot;
//Parameters seperated by $(dollar sign) in attribute.
//time is Id of HTML container that will get populated with the response.</pre>
<p>Configure <em>Web.config</em> to use this <code>HttpModule</code>: </p>
<pre>&lt;system.web&gt;
	&lt;httpModules&gt;
		&lt;add name=&quot;SomeDummyHttpModuleExample&quot;
			type=&quot;SomeDummyHttpModuleExample.HttpModuleExample&quot;/&gt;

	&lt;/httpModules&gt;

&lt;/system.web&gt;</pre>
<p>To read assembly information, I use <code>appdomain</code> to get the list of all loaded assemblies and then search for the specific type and calling its <code>static </code>method with parameters or without parameters. </p>
<p>You can use&#8230; </p>
<pre>if (aaa.GlobalAssemblyCache == true)
    continue;</pre>
<p>&#8230; to avoid checking the type of all assemblies in module. </p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.yoursearchbuddy.com/httpmodule-handle-ajax-calls/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

