一种简易的html数据提交到后台的方法,该如何修改代码呢?

E:/前端/Test.html

<!DOCTYPE html>
<head>
    <title>Test</title>
</head>
<body>
    <div id="id">
        用户名:<input name="username" type="text"/>
        密码:<input name="password" type="password"/>
        <button type="submit" onclick="Test()">提交</button>
    </div><!--修改为div-->

    <script>
        function Test(){
            

            $.ajax({
                url:url,
                type:type,
                data:data,
                dataType:dataType,
            })
        }
    </script>
</body>

E:/后端

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="后端.Test" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>
    </form>
</body>
</html>


后面的是建立在VS2022的项目文件夹下面的

img


如果本机的地址是192.168.0.x,要如何实现

ajax提交的话需要用到js更新内容。不过没看明白test.html和test.aspx什么关系?test.html也要放到后端中,如果是另外一个项目可能会出现跨域错误,除非用的虚拟目录。

将test.html放到和test.aspx同一个目录中,然后用下面的代码进行提交和获取数据,注意ajax提交的数据在服务器端要用Request对象获取。之前写给题主的示例已经有了的啊?有什么问题可以继续交流~

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632