【发布时间】:2015-04-25 02:26:35
【问题描述】:
这里必须缺少一些基本的东西。我在本地运行的 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 谢谢
【问题讨论】:
-
您的端口号必须与您托管的端口相匹配。但是如果你得到一个 404,这意味着有东西在那个端口上监听,它只是不知道页面在哪里,或者它没有正确映射到特定的资源。
-
不相关,
success已过时,.done是要走的路。请在api.jquery.com/jquery.ajax阅读弃用通知 -
哦,好的,谢谢,没有意识到成功已经过时了
标签: c# jquery asp.net webmethod