AJAX Through JavaScript in ASP.NET:

AJAX means Asynchronous JavaScript and XML. AJAX is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications.

Even though Web development is getting more and more popular, users still experience the nasty part of having to click a button, wait until a new page loads, click another button,wait until a new page loads, and so on. But with Ajax, you can communicate with the server behind the scenes without page refresh.

With AJAX you can feel webapplication as a Desktop application because AJAX enables your web application to do the work behinde the scene.

Here I am explaining about AJAX in Asp.Net using client-side Framework.

We need some javascript function to check whether browser will suitable for AJAX or not.

    
function GetXmlHttpObject() { var objXMLHttp=null; try{ // Firefox, Opera 8.0+, Safari objXMLHttp=new XMLHttpRequest(); } catch (e){ // Internet Explorer try{ objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Your browser does not support AJAX!"); return false; } } } return objXMLHttp; }

In the above code I created the object for XMLHttpRequest to validate the Firefox, Opera 8.0+, Safari Browser.
If the browser is not in the list, I created the object for ActiveXObject to validate the internet explorer.


The total function returns the XMLHttp obect based on your Browser.

Now you need to open this XMLHttp object.

xmlHttp.open(method, URL, asyncFlag)

xmlHttp.open method requires the three parameters.
Those are method type, URL of the backend page and asyncFlag.


Method type: The HTTP method used to open the connection, such as GET, POST, PUT, HEAD, or PROPFIND.

URL: The requested URL. i.e, backend page URL.

asyncFlag: A Boolean value indicating whether the call is asynchronous. The default is true.


xmlHttp=GetXmlHttpObject() if (xmlHttp==null) { alert("Browser does not support HTTP Request"); return; } var url = 'Ajaxdisplay.aspx'; var pars = 'name=' + name; xmlHttp.open("POST",url,true)

You can find xmlHttp.open method in the above code.


Next >>

Recent Articles

CLR integartion in SQL Server
Create, Read and Write Files in .Net
Message Queue in .Net
Deploy Asp.Net Web Site
Queues in Vb.Net
If you have any queries or doubts post at Forum
Share on Facebook
Responses(post your response or comments below)
Name *

Email * (won't be published)

Response *