Ich habe versucht, den folgenden Fehler für mehrere Stunden ohne Lösung zu debuggen (Ich möchte die Tastatur in zwei Hälften brechen). Bitte helfen Sie. Ich brauche es.ASP.NET JavaScript Funktion undefined
<asp:Button ID="btnCalculate" runat="server" Text="Calculate" OnClientClick="callAjaxMethod()"/>
The 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);
}
});
}
-Code aus der ASMX-Datei:
Unhandled exception at line 90, column 95 in http://localhost:51770/SimpleAjax.aspx
0x800a1391 - JavaScript runtime error: 'callAjaxMethod' is undefined
Diese Methode von einer Schaltfläche auf einer Seite wird genannt
/// 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);
}
}
}
Gibt es einen anderen Javascript-Code innerhalb der 'script' blockieren? Manchmal ist eine Funktion aufgrund eines Problems in einem anderen Teil des Client-Codes nicht definiert. – ConnorsFan
Wie überprüfe ich das in VS 2015? –
Wenn 'callAjaxMethod' in einem 'script'-Block ist, gibt es irgendeinen anderen Code innerhalb desselben Blocks? – ConnorsFan