솔루션을 사용하지 않고 몇 시간 동안 다음 오류를 디버깅하려고했습니다. 키보드를 반으로 나누고 싶습니다. 도와주세요. 나는 그것을 필요로한다.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' 내에서 다른 자바 스크립트 코드가 있습니까? 경우에 따라 클라이언트 코드의 다른 부분에서 문제가 발생하여 함수가 정의되지 않은 경우가 있습니다. – ConnorsFan
VS 2015에서 어떻게 확인합니까? –
'callAjaxMethod'가'script' 블록 안에 있다면, 같은 블록 안에 다른 코드가 있습니까? – ConnorsFan