Call WebServices from JavaScript without using ScriptManager in asp.net

只愿长相守 提交于 2020-01-01 19:09:24

问题


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.


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

    }


来源:https://stackoverflow.com/questions/15359949/call-webservices-from-javascript-without-using-scriptmanager-in-asp-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!