Jquery 调用WebService和Wcf
来源:互联网 发布:反p2p软件 编辑:程序博客网 时间:2024/05/19 09:03
来自:http://shashoutian2005.blog.163.com/blog/static/16854152010073400573/
一、调用WebService
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title> <script src="Js/Jquery.js" type="text/javascript"></script> <script type="text/javascript">// $(function(){// alert("Hello!");// }); </script> <script type="text/javascript"> /* contentType:(默认: "application/x-www-form-urlencoded") 发送信息至服务器时内容编码类型。 dataType:预期服务器返回的数据类型。 如果不指定,jQuery 将自动根据 HTTP 包 MIME 信息返回 responseXML 或 responseText, 并作为回调函数参数传递 */ //不设置dataType和contentType属性 function callBack() { $.ajax({ type:"post", url:"WebService/MyWebService.asmx/HelloWorld", success:function(result){ alert(result); alert(result.text); }, error:function() { alert("请求服务失败!"); } }); } //不设置dataType属性 function callBack2() { $.ajax({ type:"post", contentType: "application/json", url:"WebService/MyWebService.asmx/HelloWorld", data:"{}", success:function(result){ alert(result); }, error:function() { alert("请求服务失败!"); } }); } //同时设置dataType和contentType属性 function callBack3() { $.ajax({ type:"post", contentType:"application/json",// dataType:"text",//text,html url:"WebService/MyWebService.asmx/HelloWorld", success:function(result){ alert(result); }, error:function() { alert("请求服务失败!"); } }); } function callBack4() { $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WebService/MyWebService.asmx/HelloWorld", data:"{}", success:function(result){ alert(result); alert(result.d); }, error:function() { alert("请求服务失败!"); } }); } //传递参数 function callBack5() { $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WebService/MyWebService.asmx/SayHello", data:"{name:'wangwei',content:'I love you'}", success:function(result){ alert(result); alert(result.d); }, error:function() { alert("请求服务失败!"); } }); } //返回集合 function callBack6() { $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WebService/MyWebService.asmx/GetArray", //data:'{"i":"10"}', //data:"{i:'10'}", data:"{i:10}", success:function(result){ alert(result.d.join(" | ")); $(result.d).each(function() { //alert(this.toString()); $('#dictionary').append(this.toString() + " "); }); }, error:function() { alert("请求服务失败!"); } }); } //返回集合 function callBack7() { $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WebService/MyWebService.asmx/GetUserInfos", data:"{}", success:function(result){ $(result.d).each(function() { //alert(this.toString()); $('#dictionary').append(this["UserName"] + " "+this["UserAge"]+"<br />"); }); }, error:function() { alert("请求服务失败!"); } }); } //返回XML function callBack8() { $.ajax({ type:"post", //contentType: "application/xml", dataType:"xml", url:"WebService/MyWebService.asmx/GetXMLUserInfos", data:"{}", success:function(result){ //alert(result);//将dataType设置为text时可查看XML字符串内容 $(result).find("Table1").each(function() { $('#dictionary').append($(this).find("UserName").text() + " "+$(this).find("UserAge").text() +"<br />"); }); }, error:function() { alert("请求服务失败!"); } }); } </script> </head><body> <form id="form1" runat="server"> <div> <a href="javascript:callBack6();">HelloService</a> </div> <div id="dictionary"></div> </form></body></html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>无标题页</title> <script src="Js/Jquery.js" type="text/javascript"></script> <script type="text/javascript"> /* 注意:参数格式和WebService的区别,传递参数时的格式为----data:'{"key1":"value1","key2","value2"}' jQuery调用WCF的要点: 1. binding="webHttpBinding" 2. <enableWebScript/> 允许ajax调用 */ function callBack() { $.ajax({ type:"post", dataType:"json", url:"WCF/MyWcfService.svc/SayHello", success:function(result){ alert(result.d); }, error:function() { alert("请求服务失败!"); } }); } function callBack2() { $.ajax({ type:"post", contentType:"application/json", dataType:"json", url:"WCF/MyWcfService.svc/SayHelloToSomeOne", data: '{"name":"张三"}', success:function(result){ alert(result.d); }, error:function() { alert("请求服务失败!"); } }); } //返回集合 function callBack3() { var i=10; $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WCF/MyWcfService.svc/GetArray", //data:'{"i":"10"}', //data:'{"i":"'+i+'"}', data:'{"i":'+i+'}', success:function(result){ alert(result.d.join(" | ")); $(result.d).each(function() { //alert(this.toString()); $('#dictionary').append(this.toString() + " "); }); }, error:function() { alert("请求服务失败!"); } }); } //返回集合 function callBack4() { $.ajax({ type:"post", contentType: "application/json", dataType:"json", url:"WCF/MyWcfService.svc/GetUserInfos", data:"{}", success:function(result){ $(result.d).each(function() { //alert(this.toString()); $('#dictionary').append(this["UserName"] + " "+this["UserAge"]+"<br />"); }); }, error:function() { alert("请求服务失败!"); } }); } </script></head><body> <form id="form1" runat="server"> <div> <a href="javascript:callBack2();">HelloService</a> </div> <div id="dictionary"></div> </form></body></html>web.config<system.serviceModel> <behaviors> <endpointBehaviors> <behavior name="NewBehavior"> <enableWebScript /> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="AjaxCallService.WCF.MyWcfServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> <!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />--> <services> <service behaviorConfiguration="AjaxCallService.WCF.MyWcfServiceBehavior" name="AjaxCallService.WCF.MyWcfService"> <endpoint address="" behaviorConfiguration="NewBehavior" binding="webHttpBinding" bindingConfiguration="" contract="AjaxCallService.WCF.IMyWcfService"> <identity> <dns value="localhost" /> </identity> </endpoint> <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> </service> </services> </system.serviceModel>
- Jquery 调用WebService和Wcf
- 抛弃WebService 在.NET4中用jQuery调用WCF
- 抛弃WebService,在.NET4中用 jQuery 调用 WCF
- 抛弃WebService,在.NET4中用 jQuery 调用 WCF
- 抛弃WebService 在.NET4中jQuery调用WCF
- 抛弃WebService 在.NET4中用jQuery调用WCF
- 抛弃WebService 在.NET4中用jQuery调用WCF
- 抛弃WebService,在.NET4中用 jQuery 调用 WCF
- WCF 调用webservice
- VB6调用WebService、WCF
- Android使用Json和ksoap2调用WebService(WCF)
- Jquery(Ajax) 调用wcf
- WCF Jquery 调用
- JQuery 调用 WCF示例
- jQuery调用WCF
- jquery 调用wcf
- JQuery调用WCF
- 什么是wcf?wcf和webservice的区别
- 理解/proc文件系统
- 北京副市长要求地铁车厢不得超载
- iPhone编译和运行
- .net2.0中读取xml文件方法
- lambda表达式
- Jquery 调用WebService和Wcf
- repository assumed
- 主窗口隐藏方法
- Installshield
- QML: component
- ODBC数据库操作方式来查找错误信息的方法
- QML:动画概念
- 系统开发在设计时需要注意的地方
- QML理解