下面是我的C#和
JavaScript 代码,我可以访问这个方法,但我没有得到预期的输出
来自“成功”:
success: function( msg ){
alert( msg.d );
}
相反,它返回 [object object]
Javascript:
$.ajax({
type: "POST",
url: "Home.aspx/UpdateSelectionStatus,
data: '{id_ver: "' + id + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function(msg){alert(msg.d);},
failure: function(){ }
});
C#:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string UpdateSelectionStatus(string id_ver){
return "success" + id_ver;
}
最佳答案
这就是错误:
alert(msg.d);
直接使用msg即可:
success: function (msg) {alert(msg); },
你返回了一个简单的字符串,而不是一个复杂的类型,所以你没有任何像“d”这样的属性。
关于c# - 在 asp.net 中使用 ajax 访问 C# 方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21040558/