【问题标题】:Comuinicating with server与服务器通信
【发布时间】:2020-05-13 00:11:45
【问题描述】:

我需要让我的 http 服务器能够从客户端接收字符串并将它们存储在服务器上。目前我使用 XAMPP-Apache-http(我不知道,哪些信息有帮助)服务器,上面有一个简单的 index.html,但如果它不可能,我云也使用另一个程序。我想使用 JSON 来传输数据,但首先我需要为它配置一个 socked。

我认为这是通过在服务器上安装一个脚本来完成的,该脚本向客户端发送一个 Socked 服装以进行通信。但我不知道这个脚本是否会被放置在正常的 /htdos 中对我有意义,因为它会在客户端运行(我是否还需要另一个脚本)。我想我误解了一些基本的想法。另外:在端口 80 上进行客户端和服务器通信?如果他们这样做,我需要更改预设端口还是只使用脚本或其他应用程序...

html:

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>

<body>
    <input type="text" id="some_Text" name="some_Text" />

    <button type="submit" id="SEND_button" name="SEND_button" onclick="myFunction()">SEND</button>

    <script type="text/Javascript">
        function myFunction() {
            var thatText = document.getElementById('some_Text').value;


            alert(thatText);


            window.location.replace("https://google.com/");
        }
    </script>
</body>

insted 的 alert(thatText) 我想将 thatText 发送到服务器。

希望有人可以帮助我。

【问题讨论】:

    标签: javascript html json apache websocket


    【解决方案1】:

    您可以使用 ajax 并发送一个 post 请求:

    $.ajax({
        type: 'POST',
        url: '<< URL >>',
        data: {
            "text": thatText
        },
        success: function (response) {
            alert('Done');
        },
        error: function (jqXHR, exception) {
            alert('Error');
        },
    });
    

    【讨论】:

    • 拳头,感谢您的回答。可悲的是,我没有足够的时间来理解它,但我能看到的第一个问题是,我不知道 ajax 是什么,即使使用谷歌,我也无法理解 sintax。但是感谢您的回答,我会尽力理解它:)。
    • @ErikEverythingLUL 有很多关于 Ajax 的文档:w3schools.com/whatis/whatis_ajax.asp
    • 谢谢,我需要一些时间,但我得到了它的工作: var input = $("#some_Text").val();在 $.ajax: url: 'input.php' , data: "input=" + input, .然后输入。 php: 如果有人和我有同样的问题:你可以通过添加:成功:函数(结果){ > }
    • @ErikEverythingLUL 干得好......有很多方法可以做到这一点:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 2011-09-23
    • 2021-12-29
    • 1970-01-01
    • 2014-03-07
    • 2021-09-13
    相关资源
    最近更新 更多