Recently, I have been attempting to execute a C# method from JavaScript within my ASP.NET page named parameters.aspx. However, each time I hit the button to trigger the method, an error 404 is displayed.
Let's take a look at the C# method defined in parameters.aspx.cs:
[WebMethod]
public void MethodSearch()
{
// Searching for relevant information
string _sEnrollmentEsiid;
string _sEnrollmentAddress;
string _sEnrollmentCity;
string _sEnrollmentZipCode;
GetDistributionPointsRequest disRequest = new GetDistributionPointsRequest();
_sEnrollmentEsiid = disRequest.EsiID;
_sEnrollmentAddress = disRequest.Address;
_sEnrollmentCity = disRequest.City;
_sEnrollmentZipCode = disRequest.Zip;
}
Next, here is the corresponding JavaScript function:
<script type="text/javascript">
function testFunction() {
$.ajax({
type: "POST",
url: 'http://localhost:63788/parameters.aspx/MethodSearch',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#divResult").html("success");
},
error: function (e) {
$("#divResult").html("Something Went Wrong.");
}
});
}
</script>
Lastly, this is how I am calling the function in HTML:
<a href class="btn btn-danger" onclick="testFunction()">Test</a>
<label id="divResult"></label>
I am struggling to pinpoint what exactly is causing the issue. The error message being returned is:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)