Skip to content Skip to sidebar Skip to footer

Call Asp.net Web Service From Javascript Client

I have a previously written client-server application(by another programmer). The client side is written with javascript. I need to write a new web service with ASP.net but I don't

Solution 1:

refer the following links wish will provide you complete guide on how to call web service using JavaScript/Asp.net Ajax or jQuery.

http://cmsnsoftware.blogspot.com/2011/01/how-to-call-csharp-function-in-ajax.html

http://cmsnsoftware.blogspot.com/2011/02/how-to-use-ajax-auto-complete-in-aspnet.html

sample code

if (window.XMLHttpRequest) {
    // for IE7+, Firefox, Chrome, Opera, Safarithis.xmlhttp = new XMLHttpRequest();
}
else {
    // for IE6, IE5try {
        this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
        try {
            // older version of Msxmlthis.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (e2) {
            this.xmlhttp = null;
        }
    }
}
xmlhttp.onreadystatechange = function() {
    /// <summary>/// Display server time when success/// </summary>if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        // success Status
        alert(xmlhttp.responseText);
    }
}
this.xmlhttp.open("POST", "AjaxServer.asmx/WebMethodName", true);
this.xmlhttp.send();

Post a Comment for "Call Asp.net Web Service From Javascript Client"