Javascript 没有调用Ajax PageMethods
我有以下javascript在asp.net中调用webmethdJavascript 没有调用Ajax PageMethods,javascript,jquery,asp.net,ajax,Javascript,Jquery,Asp.net,Ajax,我有以下javascript在asp.net中调用webmethd function passpd(elem) { if (confirm("You sure you want to delete") == true) { var exID = $(elem).closest('table').attr('id'); exID = exID.replace("_fawad", ''); alert(exID
function passpd(elem) {
if (confirm("You sure you want to delete") == true) {
var exID = $(elem).closest('table').attr('id');
exID = exID.replace("_fawad", '');
alert(exID + "abc");
PageMethods.DeleteInfo1("fawad", exID, "OnSuccessD", "OnErrorD");
alert("2");
var d1= $(elem).closest('table').attr('id');
$("#" + d1).remove();
return false;
}
else { alert("cancel deletion");return false;}
}
我的方法如下:
[WebMethod]
public static string DeleteInfo1(string pname, string id)
{
string constr = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ProfileOne.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(constr);
string sql = "delete from Experience where ProfileName=@p and ExperienceID=@e";
SqlCommand cmd = new SqlCommand(sql, con);
cmd.Parameters.Add("@p", SqlDbType.VarChar).Value = pname;
cmd.Parameters.Add("@e", SqlDbType.Int).Value = Convert.ToInt32(id);
con.Open();
int ret = cmd.ExecuteNonQuery();
if (ret > 0) { return "ok"; }
else { return "nok"; }
}
问题是网络方法没有被调用。正在调用passpd函数中的第一个警报,但未执行PagemHods.DeleteInfo1
问题是什么。请帮忙
谢谢您必须在该方法上发表文章。我不确定您在发布后所做的事情是否取决于操作的结果,但如果是,您必须将其放在$.post中,此处为//do something
我找到了解决办法 我是用url重写的,所以。当我检查代码的时候,我突然想到了
function passpd(elem) {
if (confirm("You sure you want to delete") == true) {
var exID = $(elem).closest('table').attr('id');
exID = exID.replace("_fawad", '');
alert(exID + "abc");
$.post('/PageMethods/DeleteInfo1/', { pname: 'fawad', id: exID }, function() {
//do something here?
});
alert("2");
var d1= $(elem).closest('table').attr('id');
$("#" + d1).remove();
return false;
}
else { alert("cancel deletion");return false;}
}