2

I have created a Web service for my Asp.net project. At present I'm accessing the service from JavaScript by referencing the Service in ScriptManager. But I don't want to add a ScriptManager so that I can use it in any HTML page.

4
  • so you want to call your webservice using JavaScript ajax not by using ScriptManager ?? Commented Mar 12, 2013 at 11:34
  • Ya Exactly!!! Also need to pass parameters Commented Mar 12, 2013 at 11:36
  • 1
    You can always write your own Javascript and/or use a library (e.g. Jquery) if you want and build your own Ajax requests and parse responses. Commented Mar 12, 2013 at 11:37
  • I found something , but it doesn't say how to pass parameters. My method requires two string inputs Commented Mar 12, 2013 at 11:41

1 Answer 1

1

Ok. so you want to make ajax call to some web-service method and pass parameters to it. And you are going to pass the parameters as JSON format

function CallWebServiceMethod() {
     var requestedData = "{ 'LifeCycleN': '" + var_LifeCycleN +//var_LifeCycleN some var represent your data that you want to send
            "', 'LiOrder': '" + var_LiOrder +//var_LiOrder again some var represent your data that you want to send
            "'}";
    $.ajax({
        type: "POST",
        url: "Services/YouWebServiceName.asmx/WebServiceMethodName",
        data: requestedData,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {// I 'll assume that your web-service 'll return bool value indicate if the operation done successfully or not.
        //do here what you want to do is the request was successful.
        }
    });

    }
Sign up to request clarification or add additional context in comments.

13 Comments

Ya this is what I Exactly wanted. Let me try it! Thank You
if you want me to explain more just tell me.
[WebMethod] public static void GetStageList(string LifeCycleN, string LiOrder)
This is how my webservice accepts values. then how should i `var requestedData'must be
i updated the code..please tell me which part is not working or what's the error you get?
|

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.