I am attempting to create a webmethod that I can call/POST to from javascript code, but I obtain the following error in console whenever the test() function is called:
"POST http://localhost:53093/TestMethods.asmx/HelloWorld 404 (Not Found)"
I have checked multiple questions similar to mine, but none of the solutions seem to work. Any help would be appreciated.
TestMethods.asmx.cs
[WebService(Namespace = "http://testdomain.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class TestMethods : System.Web.Services.WebService
{
[WebMethod()]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string HelloWorld()
{
return "Hello World";
}
}
Javascript (game.js)
function test()
{
$.ajax({
url: "TestMethods.asmx/HelloWorld",
type: 'POST',
data: "{}",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) {
alert(result);
}
});
}