[英]How do I make an html file include itself without refreshing the page each time a button or link is clicked?
Beginner's question here : 初学者的问题在这里:
file #1 : file1.html (one dataset) 文件#1:file1.html(一个数据集)
//header, body and some other stuff
<form action="some_logic.php">
<input type="text" name="data1" placeholder="data1">
<input type="text" name="data2" placeholder="data2">
<input type="submit" value="Ok!">
</form>
//end of the html
file #2 : (I don't even know what this file should be : php? html? js?) 文件#2 :(我什至不知道该文件应该是什么:php?html?js?)
//usual stuff
include 'file1.html'; //OR
<!--#include file="file1.html"-->
#logic to replicate file1.html with a button
I need to have the file1's code repeated once each time the user clicks on a button (or a link or whatever) and I would like this to work without refreshing the page (or at least without questionning the server over and over and without deleting the current datas). 每次用户单击按钮(或链接等)时,我都需要重复一次file1的代码,并且我希望此方法能够在不刷新页面的情况下工作(或者至少在不反复询问服务器且不删除服务器的情况下)当前数据)。 The server uses php7.
服务器使用php7。
I need this because I do not know in advance how much datasets the user will create. 我需要这样做是因为我事先不知道用户将创建多少个数据集。 It would be awesome if this could be done with javascript!
如果可以用javascript完成,那就太好了! (since I doubt this can be achieved with php/html only) Although I have never used js until now.
(因为我怀疑这只能通过php / html来实现),尽管到目前为止我从未使用过js。
You can fetch data from server without refreshing the webpage using JavaScript Ajax. 您可以使用JavaScript Ajax从服务器获取数据而无需刷新网页。 Here you can create an event listener to send a request to the server.
在这里,您可以创建一个事件侦听器来向服务器发送请求。 The data can be plain text, html, json, xml or whatever you want.
数据可以是纯文本,html,json,xml或任何你想要的。 Just create Ajax request for events.
只需为事件创建Ajax请求。 Then update the webpage using the response data.
然后使用响应数据更新网页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.