Jquery、Ajax Web 方法出现错误 404 url

Jquery, Ajax Error 404 with Webmethod url

我进行了大量搜索,发现的所有内容都表明我的设置应该有效(似乎没有人遇到我的确切问题,我似乎也没有遇到其他人的问题)。

我以前作为实习生做过这件事,但我没有设置,现在我正在尝试从头开始做所有事情,尽可能接近我以前的做法,并边学边做。我只是想从我的网络方法中得到回复。一旦我开始工作,我就可以继续前进。让我知道你们的想法...

producs.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Product</title>
<link href="Content/styles.css" rel="stylesheet" />
<!-- Bootstrap -->
<link href="Content/bootstrap.css" rel="stylesheet" />
<link href="Content/bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Calendar -->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
</head>

<body>
...
    <div class="buttonsInline">
        <button class="btn btn-info btn-lg" onclick='Test()' style="float:none">Alert</button>
    </div>
...
</body>
</html>

<script>
function getVendorSystem() {
    var system = sessionStorage.getItem('setSystem');
    var vendor = sessionStorage.getItem('setVendor');

    alert("System: " + system + "\nVendor: " + vendor);
}


function Test() {

    $.ajax({
        method: 'post',
        url: "WebNet.aspx/MSG",
        data: '{}',
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: "true",
        cache: "false",
        success: function Succeed() {

            alert("SUCCESS!");
        },
        error: function Error() {
            alert("An Error Occured.")
        }
    });
}
</script>

WebNet.aspx.vb

Imports System.Web.Services
Imports System.Data.SqlClient

Public Class WebNet
    Inherits System.Web.UI.Page

    <WebMethod()>
    Public Shared Function MSG()
        MsgBox("Updated")
        'Dim sqlConnection1 As New SqlConnection("Your Connection String")
        'Dim cmd As New SqlCommand
        'Dim reader As SqlDataReader

        'cmd.CommandText = "SELECT * FROM Customers"
        'cmd.CommandType = CommandType.Text
        'cmd.Connection = sqlConnection1

        'sqlConnection1.Open()

        'reader = cmd.ExecuteReader()
        ' Data is accessible through the DataReader object here.

        'sqlConnection1.Close()
        Return 0

    End Function

End Class

WebNet.aspx

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="WebNet.aspx.vb" Inherits="WebApplication1.WebNet" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

我收到错误 404。对 url 使用 Action 给我错误 400。
只需输入 URL http://localhost:63787/WebNet.aspx/MSG gives me 404, but http://localhost:63787/WebNet.aspx 就可以了,这是应该的。

尝试键入包含 WebMethod 的 aspx 的完整路径,或尝试将整个脚本移动到包含 webmethod 的 aspx。

您可以尝试将 as String 添加到您的函数中(Public Shared Function MSG() as String)

此致

正如我所想,这不是我写的代码。我花了 3 天时间检查它,我当然希望不会....但这似乎暂时解决了它。