解決策なしで数時間にわたって次のエラーをデバッグしようとしました(キーボードを半分に分割したい)。助けてください。それが必要。ASP.NET JavaScript関数が定義されていません
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClientClick="callAjaxMethod()"/>
JS:
function callAjaxMethod()
{
// e.preventDefault();
$.ajax({
type: "POST",
url: "SimpleAjax.asmx/IsLeapYear",
data: '{year: "' + $("#<%=txtYear.ClientID%>").val() + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response.d) {
$('#<%=txtResult.ClientID%>').val('Leap Year');
}
else {
$('#<%=txtResult.ClientID%>').val('Not a Leap Year');
}
},
failure: function (response) {
$('#<%=txtResult.ClientID%>').val("Error in calling Ajax:" + response.d);
}
});
}
コードASMXファイルから:
/// Summary description for SimpleAjax
/// </summary>
[WebService(Namespace = "http://automatedpumpcontroller.somee.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class SimpleAjax : System.Web.Services.WebService
{
[WebMethod]
[System.Web.Script.Services.ScriptMethod()]
public static bool IsLeapYear(int year)
{
return DateTime.IsLeapYear(year);
}
}
}
Unhandled exception at line 90, column 95 in http://localhost:51770/SimpleAjax.aspx
0x800a1391 - JavaScript runtime error: 'callAjaxMethod' is undefined
この方法は、ページ上のボタンから呼び出されています
'script'ブロック内の任意の他のJavascriptコードはありますか?場合によっては、クライアントコードの別の部分に問題があるため、関数は未定義です。 – ConnorsFan
VS 2015でそれをどのようにチェックするのですか? –
'callAjaxMethod'が' script'ブロックの中にある場合、同じブロックの中に他のコードがありますか? – ConnorsFan