First of all, I am NOT using MVC (don't ask why)
From reading other posts on here it seems I need to use a "WebMethod" approach but I cannot seem to get my function to call properly.
The Chrome console gives me a 404 error "Cannot find /ajax/TestAjax". So I know I'm not locating the function correctly. But I can't seem to find where to put it.
Any advice is much appreciated!
File locations:
jQuery code:
$("#btn_adduser").click(function () {
var isValid = validateAddUser();
if (isValid.length > 2) {
alert(isValid);
}
else {
$.ajax({
type: "POST",
url: "/ajax/TestAjax",
data: "",
success: function (data) {
alert(data);
}
});
}
});
C# code: (ajax.cs)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for ajax
/// </summary>
public class ajax
{
public ajax()
{
}
[WebMethod]
public static string TestAjax()
{
return "All Good";
}
}
