在云那方

首页 新随笔 联系 订阅 管理

想测试下jQuery调用个第三方的WebService,利用 jQuery 的 $.get(url, data, callback) 调用了一个手机归属地查询的WebService。
PS: http://www.webxml.com.cn/zh_cn/index.aspx 网站里提供很多有用的简单的WebService。

  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head>  
  3.    <title>jQuery Test</title>  
  4.    <mce:script src="http://code.jquery.com/jquery-1.4.3.js" mce_src="http://code.jquery.com/jquery-1.4.3.js" language="javascript"></mce:script>  
  5.    <mce:script type="text/javascript" language="JavaScript"><!--  
  6.        $(document).ready(function () {  
  7.            $("#btnGet").click(function () {  
  8.                var url = "http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo";  
  9.                var mobile = $("#txtMobile").val();  
  10.                $.get(url, { mobileCode:mobile, userID:"" }, function (data) {  
  11.                    var result = $(data).first().text();  
  12.                    $("#divResponse").text(result);  
  13.                });  
  14.            });  
  15.        });  
  16.      
  17. // --></mce:script>  
  18. </head>  
  19. <body>  
  20. <h1>jQuery 手机号归属地查询</h1>  
  21. <div>  
  22.     MobileCode: <input id="txtMobile" type="text" style="width:100px" />  
  23.     <input type="button" id="btnGet" value="Get" style="width:80px" />  
  24. </div>  
  25.     <hr />  
  26. <div id="divResponse">  
  27. </div>  
  28. </body>  
  29. </html>  

这个服务(http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx?op=getMobileCodeInfo)需要两个参数:mobileCode 和 userID,用 json 组装起来,调用 HTTP GET 就可以了。 程序很简单,自娱自乐而已。
运行结果如下:

 

posted on 2011-11-25 12:28  Rich.T  阅读(434)  评论(0编辑  收藏  举报