用Jquery訪問(wèn)WebService并返回Json的代碼第2/3頁(yè)
test.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>Untitled Page</title>
<script src="jquery-1.2.2.js" type="text/javascript"></script>
</head>
<body>
<input type="button" onclick="requestHelloWorld();" value="請(qǐng)求HelloWorld" />
<input type="button" onclick="requestCreateUser();" value="請(qǐng)求CreateUser" />
<script type="text/javascript">
function requestHelloWorld(){
WebService('ws1.asmx/HelloWorld',function(obj){alert(obj);});
}
function requestCreateUser(){
WebService('ws1.asmx/CreateUser',function(obj){alert(obj.Name);},'{name:"林子",age:25}');
}
function WebService(url,callback,pars){
$.ajax({
data:pars,
url: url,
type: "POST",
contentType: "application/json;utf-8",
dataType:'json',
cache: false,
success: function(json){
callback(json.d);
},
error:function(xml,status){
if(status=='error'){
try{
var json = eval('(' + xml.responseText + ')');
alert(json.Message+'\n'+json.StackTrace);
}catch(e){}
}else{
alert(status);
}
},
beforeSend:function(xml){
if(!pars) xml.setRequestHeader("Content-Type", "application/json;utf-8")
}
});
}
</script>
</body>
</html>
web.config為vs2008在.net 3.5狀態(tài)下創(chuàng)建的默認(rèn)的 也有很重要的作用 這里貼出來(lái)
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
</configSections>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
</assemblies>
</compilation>
<!--
The <authentication> section enables configuration
of the security authentication mode used by
ASP.NET to identify an incoming user.
-->
<authentication mode="None"/>
<!--
The <customErrors> section enables configuration
of what to do if/when an unhandled error occurs
during the execution of a request. Specifically,
it enables developers to configure html error pages
to be displayed in place of a error stack trace.
<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</controls>
</pages>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
<!--
The system.webServer section is required for running ASP.NET AJAX under Internet
Information Services 7.0. It is not necessary for previous version of IIS.
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules>
<remove name="ScriptModule"/>
<add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</modules>
<handlers>
<remove name="WebServiceHandlerFactory-Integrated"/>
<remove name="ScriptHandlerFactory"/>
<remove name="ScriptHandlerFactoryAppServices"/>
<remove name="ScriptResource"/>
<add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</handlers>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
- 淺談對(duì)Jquery+JSON+WebService的使用小結(jié)
- jQuery調(diào)用WebService返回JSON數(shù)據(jù)及參數(shù)設(shè)置注意問(wèn)題
- 排除JQuery通過(guò)HttpGet調(diào)用WebService返回Json時(shí)“parserror”錯(cuò)誤
- jQuery結(jié)合Json提交數(shù)據(jù)到Webservice,并接收從Webservice返回的Json數(shù)據(jù)
- asp.net下使用jquery 的ajax+WebService+json 實(shí)現(xiàn)無(wú)刷新取后臺(tái)值的實(shí)現(xiàn)代碼
- jQuery調(diào)用Webservice傳遞json數(shù)組的方法
相關(guān)文章
.Net?Core3.0?WebApi?項(xiàng)目框架搭建之使用Serilog替換掉Log4j
Serilog 是一個(gè)用于.NET應(yīng)用程序的日志記錄開(kāi)源庫(kù),配置簡(jiǎn)單,接口干凈,并可運(yùn)行在最新的.NET平臺(tái)上,這篇文章主要介紹了.Net?Core3.0?WebApi?項(xiàng)目框架搭建之使用Serilog替換掉Log4j,需要的朋友可以參考下2022-02-02
自動(dòng)類型安全的REST.NET標(biāo)準(zhǔn)庫(kù)refit
這篇文章介紹了自動(dòng)類型安全的REST.NET標(biāo)準(zhǔn)庫(kù)refit,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-04-04
寫(xiě)一個(gè)含數(shù)字,拼音,漢字的驗(yàn)證碼生成類
本文和大家分享的是一個(gè)集成1:小寫(xiě)拼音;2:大寫(xiě)拼音;3:數(shù)字;4:漢字的驗(yàn)證碼生成類。本章例子也會(huì)有一個(gè)mvc使用驗(yàn)證碼校驗(yàn)的場(chǎng)景。具有一定的參考價(jià)值,下面跟著小編一起來(lái)看下吧2017-01-01
四個(gè)常用的.NET的SQLHELPER方法實(shí)例
這篇文章主要介紹了四個(gè)常用的.NET的SQLHELPER方法,在WinForm的實(shí)際開(kāi)發(fā)中比較常用,需要的朋友可以參考下2014-08-08
ASP.NET 頁(yè)面中動(dòng)態(tài)增加的控件、添加事件
在ASP.NET中動(dòng)態(tài)創(chuàng)建一個(gè)控件總是不那么順利,特別是當(dāng)對(duì)頁(yè)面的Life Cycle不是那么了然的情況下!這里簡(jiǎn)單描述一下要求,然后提供一個(gè)解決方案,大家看看有沒(méi)有更好的Idea,如果有的話就是我的大幸了,呵呵!2009-07-07
如何在.NET Core應(yīng)用中使用NHibernate詳解
NHibernate 是一個(gè)基于.Net 的針對(duì)關(guān)系型數(shù)據(jù)庫(kù)的對(duì)象持久化類庫(kù)。下面這篇文章主要給大家介紹了關(guān)于如何在.NET Core應(yīng)用中使用NHibernate的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2018-08-08
ASP.NET內(nèi)置對(duì)象之Application對(duì)象
Application對(duì)象是HttpApplicationState類的一個(gè)實(shí)例,它可以產(chǎn)生一個(gè)所有Web應(yīng)用程序都可以存取的變量,這個(gè)變量的可以存取范圍涵蓋全部使用者,也就是說(shuō)只要正在使用這個(gè)網(wǎng)頁(yè)的程序都可以存取這個(gè)變量。2008-09-09
asp.net實(shí)現(xiàn)多個(gè)文件同時(shí)下載功能
這篇文章主要為大家詳細(xì)介紹了asp.net實(shí)現(xiàn)多個(gè)文件同時(shí)下載功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-04-04
ASP.NET?MVC實(shí)現(xiàn)樹(shù)形導(dǎo)航菜單
這篇文章介紹了ASP.NET?MVC實(shí)現(xiàn)樹(shù)形導(dǎo)航菜單的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09

