Introduction:
In this article, i am going to explain about how to call a http handler/modules using ajax.
Main:
We can easily accessing the http handlers in the same way like normal pages using
post and get method.
local_xmlrequest = XMLlocal_xmlrequestuest();
local_xmlrequest.onreadystatechange = XMLlocal_xmlrequestuestCompleted;
local_xmlrequest.open("GET", "HttpModuler.ashx?Name=" +
document.getElementById('<%=txtName.ClientID%>').value, true);
local_xmlrequest.send(null);
// initialize XMLlocal_xmlrequestuest object
function XMLlocal_xmlrequestuest() {
var xmlHttp;
try {
// Opera 8.0+, Firefox, Safari
xmlHttp = new XMLlocal_xmlrequestuest();
}
catch (e) {
// IEBrowsers
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
return false;
}
}
}
return xmlHttp;
}
function XMLlocal_xmlrequestuestCompleted()
{
if (local_xmlrequest.readyState == 4)
{
try
{
alert(local_xmlrequest.responseText);
}
catch (e)
{
}
}
}
local_xmlrequest = XMLlocal_xmlrequestuest(); local_xmlrequest.onreadystatechange = XMLlocal_xmlrequestuestCompleted; local_xmlrequest.open("GET", "HttpModuler.ashx?Name=" + document.getElementById('<%=txtName.ClientID%>').value, true); local_xmlrequest.send(null); // initialize XMLlocal_xmlrequestuest object function XMLlocal_xmlrequestuest() { var xmlHttp; try { // Opera 8.0+, Firefox, Safari xmlHttp = new XMLlocal_xmlrequestuest(); } catch (e) { // IEBrowsers try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { return false; } } } return xmlHttp; } function XMLlocal_xmlrequestuestCompleted() { if (local_xmlrequest.readyState == 4) { try { alert(local_xmlrequest.responseText); } catch (e) { } } } |
Happy coding!
nice post. thanks.