简体   繁体   English

如何使html文件包含自身,而不在每次单击按钮或链接时刷新页面?

[英]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.

相关问题 在每次对服务器进行XML调用后,如何在不刷新页面的情况下更新html表? - How do I update an html table after each XML call to the server without refreshing the page? 如何使外部参照链接在PHP包含文件中工作 - How do I make a xref link work in a PHP include file 更改内容或包含文件而不刷新页面 - Change Content or Include File Without Refreshing Page 如何在不将页面刷新到mysql数据库的同时刷新页面的情况下创建表单? - How do I create a form without refreshing the page at the same time the data goes into a mysql data base? 我如何通过jquery ajax对html元素进行永久更改,以使其在刷新页面后仍保留? - How do i make changes to an html element through jquery ajax permanent so it remains after refreshing the page? 单击按钮而不刷新页面时运行 PHP 脚本 - Run PHP script when button is clicked without refreshing page 单击按钮时,如何在没有其他代码的情况下使返回的消息显示在同一页面上? - When clicked on button, how can i make the returned message appear on the same page without other code? 如何在不刷新整个页面的情况下更改链接 - How to change the link without refreshing the entire page 如何在不刷新页面的情况下在服务器端进行文件上传验证? - How to do File upload validation Server side without refreshing the Page? 如何在不刷新页面的情况下显示错误? - How do I show an error without refreshing the page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM