Different methods to call Web Services from AJAX
来源:互联网 发布:修谱软件下载 编辑:程序博客网 时间:2024/06/05 00:47
Introduction
This article briefly explains the various ways in which a Web Service method can be called using AJAX.
Background
Lots of articles are out there explaining how AJAX and Web Services interact together while trying to solve various problems. I have put together just the interaction ways. In short, here are the different ways to call a Web Service from AJAX.
Using the code
The code below demonstrates the different methods starting with the traditional approach of No AJAX as the base.
The code snippets are arranged as:
- Web Service
- ASPX and
- C# code-behind
Before AJAX
This section can just be glanced over to see how a Web Service method used to be called on postback from a server control like a button.
No JavaScript - Postback required to populate Label1
Client ASPX:
Client code-behind:
Using AJAX
Method 1
This section explains how a Web Service can be called by modifying the ScriptManager
.
Using AJAX - Postback not required to populate Label1
- Add the
ScriptService()
attribute to the Service class. - Add the
<Services>
tag to theScriptManager
. - Convert the server controls "
Label
" and "Button
" to HTML controls. - Call the Web Service method from JavaScript which is actually a proxy call.
- Remove the Click handler from the code-behind.
Client ASPX:
Client code-behind:
Method 2
This section explains how a Web Service can be called from a CascadingDropDown Toolkit control with or without the intermediate page method.
Using AJAX page method and the CascadingDropDown control from the Toolkit- Postback not required to populate the combo
- Add a new method to the service to return the
CascadingDropDownValue[]
collection. This will act as the data source for the dropdownlists. - Remove the
<Services>
tag from theScriptManager
. - Remove
EnablePageMethods
from theScriptManager
. - Remove the label and the textbox controls.
- Add two
DropDownList
server controls and twoCascadingDropDown
s (from the Toolkit) to the client page. - Set the service name and method of the first
CascadingDropDown
. - Set the page method only for the second
Cascadingdropdown
.
Client ASPX:
Client code-behind:
Points of interest
Hope this clears out a lot of confusion especially for people trying to work out how to access Web Services. I am open to comments.
- Different methods to call Web Services from AJAX
- How to call different methods as given in an array
- RESTful Web Services - Methods
- Using jQuery to directly call ASP.NET AJAX page methods
- call Java methods from C++
- Ajax post data to sharepoint web services
- Call SOAP Web services with Ajax, Part 1: Build the Web services client
- Call SOAP Web services with Ajax, Part 2: Extend the Web services client
- How to debug ABAP Web services from Microsoft Visual Studio
- JNI - Call Method(Callback Call java methods from c)
- 4 Steps to Consume Web Services using Ajax
- Introduction to Web Services
- Android - How can I call Java methods from C++
- Returning Objects from Web Services
- Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.Net
- Notes for "Next.Generation.Application.Integration.From.Simple.Information.To.Web.Services"
- cannot call methods on masonry prior to initialization; attempted to call method 'appended' 瀑布流
- cannot call methods on button prior to initialization; attempted to call method 'toggle' 解决
- 2009年5月美国人三分之二(65%)的搜索是在谷歌搜索引擎上进行的
- .NET备份数据库并压缩 并查看已有备份
- 网管日常工作的基本内容
- //复合语句内定义变量
- 日记090628
- Different methods to call Web Services from AJAX
- 程序加载 控件 最后来到了这里
- 局域网常见故障分析及解决办法
- 网管员工作错误处理常见十宗罪
- 在南京
- 通过执行计划看sql的执行路径
- 很经典的117句惊世良言,值得一读
- chown
- 制作可执行的JAR文件包及jar命令详解