Jquery Ajax方式访问WebService
来源:互联网 发布:胡鞍钢为什么得宠知乎 编辑:程序博客网 时间:2024/06/05 23:42
上一篇博客介绍了再ASP中调用WebService(地址:),现在我们使用Jquery的Ajax方式来访问WebService。现将方法记录下来,方便今后随时查阅学习。
1.远程WebSevice方法介绍
HelloWorld方法没有参数,返回的是一个字符串“HelloWorld”
Test方法接受一个名字为tt的字符串参数,并且返回一个类似回显字符串:“your input is:输入参数tt”
2.编写页面,保存为jqueryandwebservice.html,页面具体代码如下:
<html><head><meta charset="utf-8" /><script type="text/javascript" src="js/jquery-1.7.1.min.js"></script><script type="text/javascript">$(document).ready(function(){$("#HelloWoldBtn").click(function(){$.ajax({type: "POST",contentType: "application/json",url: "http://localhost/yui/MyFirstWebService.asmx/HelloWorld",data: "",dataType: "json",success: function(result){var final_result = result.d;alert("final_result:"+final_result);}});});$("#TestBtn").click(function(){$.ajax({type: "POST",contentType: "application/json",url: "http://localhost/yui/MyFirstWebService.asmx/Test",data: "{tt:'test'}",dataType: "json",success: function(result){var final_result = result.d;alert("final_result:"+final_result);}});});});</script></head><body><div><p>Jquery Ajax调用WebService示例</p><form id="form1"><p><input type="button" id="HelloWoldBtn" value="HelloWorld" /></p><p><input type="button" id="TestBtn" value="Test" /></p></form></div></body></html>
3.点击HelloWorld按钮,结果如图:
4.点击Test按钮,结果如图:
注意:
1)Ajax请求中,需要注意的点是:contentType必须填写application/json,dataType必须是json。
2)Ajax请求返回的数据也是json格式,并且服务器返回的结果保存在d的结果中,所以必须使用result.d来获取结果。
0 0
- Jquery Ajax方式访问WebService
- jquery ajax CORS 跨域访问 WebService
- jquery.Ajax soap方式调用webservice
- jquery ajax 跨域访问- HttpClient 方式
- JQuery Ajax跨域访问方式
- jsp使用jquery通过ajax方式访问
- Jquery ajax 调用WebService 跨域访问的解决方法
- ajax——客户端访问webservice基本使用方式
- AJAX访问WebService
- Ajax访问WebService(不跨域)
- Ajax访问WebService(跨域)
- ajax访问webservice接口
- ajax jquery webservice
- jquery ajax webservice ???
- jquery ajax webservice
- Jquery Ajax WebService
- Jquery Ajax WebService
- jquery ajax 调用WebService
- 关于rtsp server的连接保持问题
- mini2440 按键驱动添加输入子系统,让按键可以真正当做键盘一样用
- SGU 133. Border 最小区间覆盖
- 两年多没写博客了,重新写起来吧
- HDU 1698 Just a Hook
- Jquery Ajax方式访问WebService
- 浅析大型网站的架构
- 数据结构伪C代码:7.图
- 启动VMware出现报错:The VMware Authorization Service is not running
- 2013计算机视觉代码合集(3)
- POJ 3259 - Wormholes
- We still found your app uses the iOS Advertising Identifier but does not include ad functionality.
- Android中IntentService的原理及使用
- 生活杂记