我想问一下,.net2005是不是不能使用jQuery调用webService?
在查询资料中,有帖子说需要加入引用
1)System.Web.Extensions;
2)using System.Web.Script.Services;
但始终没有加入,最后又看见说添加
1)Microsoft.Web.Extensions.Design.dll
2)Microsoft.Web.Extensions.dll
这两个dll,
但添加了之后,也配置了Config,但还是不能引用希望各位大侠帮帮小弟,给点建议!!!
非常感谢,献上30分做为谢礼(前不久赚来的,我的分啊~~~)
在查询资料中,有帖子说需要加入引用
1)System.Web.Extensions;
2)using System.Web.Script.Services;
但始终没有加入,最后又看见说添加
1)Microsoft.Web.Extensions.Design.dll
2)Microsoft.Web.Extensions.dll
这两个dll,
但添加了之后,也配置了Config,但还是不能引用希望各位大侠帮帮小弟,给点建议!!!
非常感谢,献上30分做为谢礼(前不久赚来的,我的分啊~~~)
解决方案 »
- 在哪里可以下载到好使的sqlserver2008```谢谢~~~~
- repeater 用jquery 动态改变样式
- js+xml动态添加到DropDownList里面的项服务器端却得不到用户选择的项的值.
- 多种水晶报表的自由切换
- 初学asp.net!熟悉.net编程环境的朋友来看看!谢谢各位了!
- session的问题
- 求在服务器生成静态html文件的方案,关键是还能添加内容到html。
- 求助:怎样在ASP。NET(VB)页面中的一个框架中打开一个网页??
- VS.NET也会发脾气!!???? 再线等待!
- ADODataSetCommand是不是ASP.net的对象
- 如何制作Activex安装包
- ViewState["hallo"] 怎样赋值。
function DiggIt(entryId, diggType, blogId) {
$.ajax({
url: 'Public/MyService.asmx/HelloWorld',
data: '{}',
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf8',
success: function(data) {
$("DigTip_"+blogId).append(data.d)
},
error: function(xhr) {
alert("提交出错,请重试。错误信息:" + xhr.responseText);
}
});
}
提示: 提交出错,请重试。错误信息:using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;/// <summary>
/// MyService 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]public class MyService : System.Web.Services.WebService { public MyService() {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
} [WebMethod]
public string HelloWorld() {
return "Hello World";
}}
url:"Digg.aspx?action="+ftype+"&id="+aid+" &time="+new Date().toString(),
type:'GET',
success:function(){
$('#newdigg').html(arguments[0]);
}
});
}
type: "POST",
url: "Public/MyService.asmx/HelloWorld",
data: "",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
success: function(data) { $("DigTip_"+blogId).append(data.d)
},
error: function(xhr) {
alert("提交出错,请重试。错误信息:" + xhr.responseText);
}
});
public void HelloWorld() {
Response.Write("Hello World");
}
ajax 其实就是请求
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService] //令WebService成功传入Json参数,并以Json形式返回结果
[GenerateScriptType(typeof(Person))] //不是必要,但推荐添加(如果Person里面再嵌套另一个复杂类型,则必要声明)
[ToolboxItem(false)]
不应该是
dataType: "json",
而应该是
dataType: "html",
可能是因为jQuery的代码
type: "POST",
url: "Public/MyService.asmx/HelloWorld",
data: "",
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: "json",
success: function(data) { $("DigTip_"+blogId).append(data.d)
},
error: function(xhr) {
alert("提交出错,请重试。错误信息:" + xhr.responseText);
}
});
而且Webservice中的必须用Context.Response.Write("")进行输出,不能用Return.
而取值 的时候直接给data,不是data.d
但 你用 dataType: "json" 获得不到 数据 应该是 你返回的不是json 格式的数据所以 dataType: "html", 然后用 Context.Response.Write("") 输出