这里一定缺少一些基本的东西。我在本地运行的 aspx 页面中从 jquery 调用 webmethod 时收到 404 错误。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="empJquery.aspx.cs" Inherits="webApiOracle.empJquery" %>
<!DOCTYPE html>
<html lang="en">
<head runat="server">
<title>jquery emps</title>
<script src="Scripts/jquery-1.10.2.min.js"></script>
<link href="../Content/bootstrap.min.css" rel="stylesheet" />
<script type="text/javascript">
$(document).ready(function () {
getEmployees();
});
function getEmployees() {
jQuery.ajax({
url: 'empJquery.aspx/Test',
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
beforeSend: function () {
alert("Start!!! ");
},
success: function (data) {
alert("a");
},
error: function (msg) { alert("Sorry!!! "); }
});
}
</script>
然后在页面后面的代码中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using webApiOracle.Models;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace webApiOracle
{
public partial class empJquery : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string Test()
{
return "Success";
}
}
}
每当我运行时,我都会收到 404 错误 我尝试将 url 更改为 /empJquery.aspx/Test 我也尝试了 localhost/empJquery.aspx/Test 和 localhost:48784/empJquery.aspx/Test 但我似乎无法得到它。我需要在网络配置中添加一些内容吗?我正在运行.net 4.5
谢谢
好的,我刚刚发现我的应用程序是混合型MVC
, Web API
, ASPX
解决方案和我的路线配置让我很困惑,所以我不得不添加:
routes.IgnoreRoute("{page}.aspx/{*webmethod}");
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)