1

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 know how to call web methods. My sitation is the same described here Call web service from javascript but it doesn't have a clear answer. (just says use WCF, I don't know how to do it) (note that my client is a totally different project from the server, suppose it is written in eclipse) I want to know how I can call the HelloWorld method that is created by default in aa ASP.net web service, from a simple html code(including js)

Thanks, Ela

1 Answer 1

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, Safari
    this.xmlhttp = new XMLHttpRequest();
}
else {
    // for IE6, IE5
    try {
        this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e1) {
        try {
            // older version of Msxml
            this.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();
Sign up to request clarification or add additional context in comments.

7 Comments

I can't use this code,this seems to be an .aspx, but I need simple html
It's not aspx, it's plain old javascript. If you can't tell the difference, then this is probably way over your head.
@Elahehkamaliha- for the above code you don't need to use asp.net. you can call asp.net webservice using above code inside html file. only thing you need to have all in same domain.
@Chamika Sandamal- I didn't mean the part you've copied. I checked the link you have posted, and I guess the javascript sample is a .aspx file(it's name is default.aspx)
@Elahehkamaliha- yes sample is an .aspx file. but you dont need .aspx file for this sample. that link shows the same task using three different methods. thats why it is in .aspx. so you can simply use it in HTML file.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.