首页 新闻 赞助 找找看

jquery 调用webservice问题

1
悬赏园豆:20 [已解决问题] 解决于 2011-11-23 18:16

在.net 2.0 中用jquery调用webservice 出错 。 但是同样的代码 我在4.0中却能成功,求解决。。。。

View Code
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default"%>

<!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="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(
function(){
$(
'#dd').click(function(){
$.ajax({
type:
"post",
url:
"Default.aspx/HelloWorld",
contentType:
"application/json; charset=utf-8",
dataType:
"json",
success:
function(json)
{
alert(json.d)
},
error:
function(err)
{
alert(
"错误消息:"+err.responseText);
},
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="dd" value="确定"/>
</div>
</form>
</body>
</html>
View Code
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Web.Script.Serialization;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static string HelloWorld()
{
return "Hello World";
}
}

 

View Code
<?xml version="1.0"?>
<!--
注意: 除了手动编辑此文件外,您还可以使用
Web 管理工具来配置应用程序的设置。可以使用 Visual Studio 中的
“网站”->“Asp.Net 配置”选项。
设置和注释的完整列表可以在
machine.config.comments 中找到,该文件通常位于
\Windows\Microsoft.Net\Framework\vx.x\Config 中
-->
<configuration>
<appSettings/>
<connectionStrings/>
<system.web>
<!--
设置 compilation debug="true" 可将调试符号插入到
已编译的页面。由于这会
影响性能,因此请仅在开发过程中将此值
设置为 true。
-->
<compilation debug="true">
<assemblies>
<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</assemblies>
</compilation>
<!--
通过 <authentication> 节可以配置
安全身份验证模式,ASP.NET
使用该模式来识别来访用户身份。
-->
<authentication mode="Windows"/>
<!--
如果在执行请求的过程中出现未处理的错误,
则通过 <customErrors> 节
可以配置相应的处理步骤。具体而言,
开发人员通过该节可配置要显示的 html 错误页,
以代替错误堆栈跟踪。

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm" />
<error statusCode="404" redirect="FileNotFound.htm" />
</customErrors>
-->
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpHandlers>
</system.web>
</configuration>
等待是一生最初的苍老的主页 等待是一生最初的苍老 | 初学一级 | 园豆:3
提问于:2011-10-25 09:47
< >
分享
最佳答案
0

我记得好像是如果异步调用webservice的话】

该类要加一个特性标记!才支持

收获园豆:10
JasNature | 菜鸟二级 |园豆:451 | 2011-10-25 21:41
其他回答(2)
0

报什么错

收获园豆:10
artwl | 园豆:16736 (专家六级) | 2011-10-26 09:38
0

知道了 在。net2.0中不能这样调用  这样调用只能是3.5或以上..

等待是一生最初的苍老 | 园豆:3 (初学一级) | 2011-11-23 18:16
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册