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.
-
so you want to call your webservice using JavaScript ajax not by using ScriptManager ??ebram khalil– ebram khalil2013-03-12 11:34:36 +00:00Commented Mar 12, 2013 at 11:34
-
Ya Exactly!!! Also need to pass parametersSubin Jacob– Subin Jacob2013-03-12 11:36:31 +00:00Commented Mar 12, 2013 at 11:36
-
1You 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.EdSF– EdSF2013-03-12 11:37:39 +00:00Commented Mar 12, 2013 at 11:37
-
I found something , but it doesn't say how to pass parameters. My method requires two string inputsSubin Jacob– Subin Jacob2013-03-12 11:41:13 +00:00Commented Mar 12, 2013 at 11:41
Add a comment
|
1 Answer
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.
}
});
}
13 Comments
Subin Jacob
Ya this is what I Exactly wanted. Let me try it! Thank You
ebram khalil
if you want me to explain more just tell me.
Subin Jacob
[WebMethod] public static void GetStageList(string LifeCycleN, string LiOrder)Subin Jacob
This is how my webservice accepts values. then how should i `var requestedData'must be
ebram khalil
i updated the code..please tell me which part is not working or what's the error you get?
|