Jquery不能调用Asp.Net2.0后台方法吗? 测试半天用Jquery调用页面的后台方法都没法调用,在方法上都加了【WebMethod】和static页没用。连调用WebService中的方法也不能调用。上网搜了下有人说是只有在Asp.net3.5里才能调用后台方法,2.0不能调用。请问是这样吗?有哪位能说明一下啊。谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我测试了下关键是它不走,这个url:页面名称/方法名称 中的方法啊。 jquery不清楚,用ajaxPro吧或者利用get或者post,即xmlhttprequest 有人说2.0不能调用后台方法 3.5就可以。 谁能告诉我是这样吗? $("#TBOldPwd").click(function() { $.ajax( { url: "ajaxmethod.aspx/checkpwd", type: "POST", data: "{ pwd: $('#TBOldPwd').val() }", dataType:"text", contentType:"application/text; charset=utf-8", success: function(data) { $("#checkresult").text(data); } } ) })一下是我的c#代码 [WebMethod] public static string checkpwd(string pwd) { string username = HttpContext.Current.Session["username"].ToString(); string mypwd; username = DataCommand.KeyCheck(username); mypwd = DataCommand.KeyCheck(pwd); string selectStr = "select * from admin where admin_username='" + username + "' and admin_password='" + mypwd + "'"; if (DataCommand.GetData(selectStr).Rows.Count == 0) { return "旧密码错误"; } return "旧密码正确"; } 偶也试过没成功,在ASMX里的方法倒是很方便就调到了 估计是url的问题,你这是实现异步验证吧,建议你使用ashx,只要建个httphandle来处理ashx的请求,url设为ashx结束的就可以。 我想用js能访问的后台代码在jquery中应该也能访问吧 JQERY +ASHX文件 类似后台了 是可以实现的,你用一下ajaxPro搜一下,网上有现成的,前台与后台是可以互相调用的 这种写法怎么看起来怪怪的以前写的一个小例子:简单的jQuery检测注册用户名http://blog.csdn.net/gdjlc/archive/2009/11/20/4840261.aspx.html $("#username").blur(function(){ $.get("checkname.ashx", {username : $("#username").val()}, function (data, textStatus){ $("#msg1").html(data).css("color","red"); } ); }) .ashx public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string username = context.Request.QueryString["username"]; if (username == "gdjlc") context.Response.Write("对不起,此用户名已注册。"); else context.Response.Write("恭喜,当前用户名可以注册。"); } 我知道可以调用ashx和asmx的 但是我现在只想用ajax调用aspx页面后台的方法 URL 路径用 完整的试试吧 中文版VS2003,默认DateTime.ToString()的问题 [分享]关于生成并发唯一性流水号的解决方案 jquery的一个异步问题 多线程与Session的访问 有关数据库连接丢失的问题. ★有有msdn关于asp.net2.0的help文档的吗? 如何快速识别客户的IP地址是属于网通还是电信? 怎样把.net页面中的表格转换成pdf 我们社区的右上角是怎么做的? 如何 结合 dreamwaver MX 和vs.c#.net 两个软件 做网站呀?》 静态页面调用JS问题~(在线等) 高分---懂线程的进,帮小弟详细解释下每句代码的意思
或者利用get或者post,即xmlhttprequest
$("#TBOldPwd").click(function() {
$.ajax(
{
url: "ajaxmethod.aspx/checkpwd",
type: "POST",
data: "{ pwd: $('#TBOldPwd').val() }",
dataType:"text",
contentType:"application/text; charset=utf-8",
success: function(data) {
$("#checkresult").text(data);
}
}
)
})
一下是我的c#代码
[WebMethod]
public static string checkpwd(string pwd) {
string username = HttpContext.Current.Session["username"].ToString();
string mypwd;
username = DataCommand.KeyCheck(username);
mypwd = DataCommand.KeyCheck(pwd);
string selectStr = "select * from admin where admin_username='" + username + "' and admin_password='" + mypwd + "'";
if (DataCommand.GetData(selectStr).Rows.Count == 0)
{
return "旧密码错误";
}
return "旧密码正确";
}
你这是实现异步验证吧,
建议你使用ashx,
只要建个httphandle来处理ashx的请求,url设为ashx结束的就可以。
搜一下,网上有现成的,前台与后台是可以互相调用的
简单的jQuery检测注册用户名
http://blog.csdn.net/gdjlc/archive/2009/11/20/4840261.aspx.html
$("#username").blur(function(){
$.get("checkname.ashx", {username : $("#username").val()},
function (data, textStatus){
$("#msg1").html(data).css("color","red");
}
);
})
.ashx public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string username = context.Request.QueryString["username"];
if (username == "gdjlc")
context.Response.Write("对不起,此用户名已注册。");
else
context.Response.Write("恭喜,当前用户名可以注册。");
}