与服务器通信

时间:2020-01-27 15:30:32

标签: javascript html json apache websocket

我需要获取http服务器,以便能够从客户端接收字符串并将其存储在服务器上。目前,我使用的是XAMPP-Apache-http(我不知道,哪些信息对您有帮助)服务器,上面只有一个简单的index.html,但是如果无法使用,我也会使用另一个程序。我想使用JSON传输数据,但是首先我需要以某种方式为它配置一个袜子。

我认为这是通过在服务器上放置一个脚本来完成的,该脚本向客户端发送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>

装有警报(thatText),我想将thatText发送到服务器。

希望有人可以帮助我。

1 个答案:

答案 0 :(得分:0)

您可以使用ajax并发送发布请求:

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