简体   繁体   中英

Call WebServices from JavaScript without using ScriptManager in asp.net

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.

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.
        }
    });

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM