欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

用Jquery訪問WebService并返回Json的代碼第2/3頁

 更新時(shí)間:2008年09月15日 22:37:34   作者:  
經(jīng)常會(huì)用JavaScript訪問asp.net的Webservice的需求,通常的方法是用asp.net ajax來解決,但asp.net ajax框架在不國內(nèi)并不經(jīng)常被使用。

test.html

復(fù)制代碼 代碼如下:

<!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)的 也有很重要的作用 這里貼出來
復(fù)制代碼 代碼如下:

<?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>

相關(guān)文章

  • asp將本地的文件上傳到服務(wù)器

    asp將本地的文件上傳到服務(wù)器

    如果你想把自己機(jī)器的圖片或者文件放到服務(wù)器上該怎么辦呢?<BR>可選有三種辦法ftp上傳、用u盤拷貝到服務(wù)器上、如果服務(wù)器支持asp上傳功能,用網(wǎng)頁瀏覽器將文件上傳到服務(wù)器上
    2015-09-09
  • 詳解c# .net core 下的網(wǎng)絡(luò)請(qǐng)求

    詳解c# .net core 下的網(wǎng)絡(luò)請(qǐng)求

    本篇文章主要介紹了詳解c# .net core 下的網(wǎng)絡(luò)請(qǐng)求,大致介紹下在.net core 下如何進(jìn)行http請(qǐng)求,主要仍然是GET和POST方法,有興趣的可以了解下
    2017-05-05
  • 使用ASP.NET?Web?API構(gòu)建Restful?API

    使用ASP.NET?Web?API構(gòu)建Restful?API

    這篇文章介紹了使用ASP.NET?Web?API構(gòu)建Restful?API的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • asp.net實(shí)現(xiàn)文件無刷新上傳方法匯總

    asp.net實(shí)現(xiàn)文件無刷新上傳方法匯總

    本文給大家介紹的是asp.net實(shí)現(xiàn)文件無刷新上傳的2種方法,分別是使用swfupload插件和uploadify插件,講述的十分細(xì)致全面,附上示例,有需要的小伙伴可以參考下。
    2015-06-06
  • C#讀取中文字符及清空緩沖區(qū)的實(shí)現(xiàn)代碼

    C#讀取中文字符及清空緩沖區(qū)的實(shí)現(xiàn)代碼

    有一個(gè)txt的中英文語料庫文件,內(nèi)容是英文一句中文一句相間的,共3000行,需要把英文句和中文句分開,放在單獨(dú)的txt文件中。
    2010-12-12
  • ASP.NET文件上傳控件Uploadify的使用方法

    ASP.NET文件上傳控件Uploadify的使用方法

    這篇文章主要為大家詳細(xì)介紹了ASP.NET文件上傳控件Uploadify的使用方法,感興趣的小伙伴們可以參考一下
    2016-03-03
  • asp.net 常用字符串處理方法

    asp.net 常用字符串處理方法

    asp.net 常用字符串處理方法,學(xué)習(xí)asp.net的朋友可以參考下。
    2010-12-12
  • ASP.NET 控件開發(fā)系列之圖片切換web控件

    ASP.NET 控件開發(fā)系列之圖片切換web控件

    剛開始學(xué)習(xí)控件開發(fā),寫了一個(gè)web圖片切換控件,歡迎大家拍磚.
    2010-04-04
  • Visual Studio 2017安裝心得總結(jié)

    Visual Studio 2017安裝心得總結(jié)

    這篇文章主要為大家詳細(xì)總結(jié)了Visual Studio 2017安裝心得,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • ADO.NET 讀取EXCEL的實(shí)現(xiàn)代碼((c#))

    ADO.NET 讀取EXCEL的實(shí)現(xiàn)代碼((c#))

    經(jīng)常需要在數(shù)據(jù)庫與Execl之間互導(dǎo)數(shù)據(jù)。net時(shí)代,ADO.NET可以使用使用Microsoft.Jet.OleDb訪問訪問Excel,網(wǎng)上已經(jīng)有很多類似的資源,最典型也是最簡單的可能如下:(asp.net環(huán)境)
    2012-12-12

最新評(píng)論