【发布时间】:2017-09-29 07:22:27
【问题描述】:
首先,我没有使用 MVC(不要问为什么)
通过阅读此处的其他帖子,我似乎需要使用“WebMethod”方法,但我似乎无法正确调用我的函数。
Chrome 控制台给我一个 404 错误 "Cannot find /ajax/TestAjax"。所以我知道我没有正确定位函数。但我似乎找不到放置它的位置。
非常感谢任何建议!
文件位置:
jQuery 代码:
$("#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# 代码:(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";
}
}
【问题讨论】:
标签: c# jquery asp.net ajax razor