How can I call web service methods from javascript?

馋奶兔 提交于 2019-12-18 04:52:16

问题


Is there any way to call web services from javascript? I know you can add in a script manager to pull in the web services but I can't figure out how to access the functions from javascript once I've done that.

Thanks,
Matt


回答1:


Please see Calling Web Services from Client Script in ASP.NET AJAX:

This topic explains how to use to call a Web service from ECMAScript (JavaScript). To enable your application to call ASP.NET AJAX Web services by using client script, the server asynchronous communication layer automatically generates JavaScript proxy classes. A proxy class is generated for each Web service for which an <asp:ServiceReference> element is included under the <asp:ScriptManager> control in the page.




回答2:


See Using jQuery to Consume ASP.NET JSON Web Services by Dave Ward.

$(document).ready(function() {
  $.ajax({
    type: "POST",
    url: "RSSReader.asmx/GetRSSReader",
    data: "{}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      // Hide the fake progress indicator graphic.
      $('#RSSContent').removeClass('loading');

      // Insert the returned HTML into the <div>.
      $('#RSSContent').html(msg.d);
    }
  });
});


来源:https://stackoverflow.com/questions/1949688/how-can-i-call-web-service-methods-from-javascript

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