[英]Method called from codebehind with ajax return undefine
我想從代碼背后獲取價值,然后我使用ajax對其進行調用,但我一無所獲,成功的只是顯示undefine,這里的代碼
function PopMensaje() {
$.ajax({
type: "POST",
url: "/WebForms/Modulo Tramites/ProcesosTramites/frmIniciarTramite.aspx/metodoajax",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert("retorno "+result.d);
},
error: function () {
alert('Ocurrio un error');
}
});
在通話節目中
};
這是代碼背后的功能
[WebMethod]
public static string metodoajax(){
return "123";
}
在通話中顯示“ retorno undefine”。我希望它顯示“ retorno 123”
我做錯了什么? 如何解決這個問題?
您的功能正常。 我認為您在Webform中缺少了jQuery,並且在javascript函數中沒有了以下括號:
<head runat="server">
<script src="Scripts/jquery-2.1.4.min.js" type="text/javascript"></script>
</head>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.