我从 w3school 阅读了一些关于 ajax 的教程。我假设服务器如何自动接收来自客户端的消息。我有两页,一页用于客户端,一页用于服务器。当有人键入内容并单击提交时,服务器页面将自动附加到屏幕上。这就是我使用的:
client:
<script>
$(function(){
$("#submit").click(function(){
$.post("server.html", $("#f1").value()+"&&"+$("#f2").value(), function(){
alert("send!");
});
});
});
</script>
<input type="number" name="f1" id="f1" placeholder="first number..." />
<input type="number" name="f2" id="f2" placeholder="second number..." />
<input type="submit" id="submit" value="submit" />
server:
$(function(){
$("#pmsg").hide();
$("#msg").load("client.html", function(){
$("#pmsg").show().delay(1000).hide();
});
});
<div id="pmsg">new message</div>
<div id="msg"></div>
I can't achieve the result that I want, could someone tell me how to fix it? thx!
I solved the problem. I use php to write the message into a txt file and then use $.get to get the message from that file.