我想将数据从一个网页传输到另一个网页。但我不想使用 <form method="post">
标记,因为我的网页中没有表单。只是一些敏感数据需要转移到其他页面。
请回答以下问题:
- 有哪些方法可以将数据从一个页面传输到另一页面?
- 有哪些方法可以在不使用
<form>
的情况下将数据从一个页面传输到另一页面HTML 中的标签? - 另一个 PHP(或 ASP)页面如何读取另一个页面发送给它的数据?
最佳答案
I don't want to use the
<form method="post">
tag because there are no forms in my webpage
这并不是避免使用表单的好理由。您可以添加一个。
What are the ways to transfer data from one page to another?
- 通过 URI(在查询字符串中)
- 作为请求正文的一部分(POST 请求)
- 通过cookie(可以用JS设置)
- 通过各种local storage systems
如果数据需要可添加书签,请使用查询字符串。如果在服务器上进行更改(例如添加或编辑数据库条目),请使用 POST 请求(带有表单)。如果数据需要在整个站点中保留,请使用 cookie(最好在使用方法 1 或 2 后通过 HTTP 设置)。将本地存储用于需要离线运行的 Web 应用程序。
What are the ways to transfer data from one page to another without using tag in HTML?
如上所述,但要折扣 post 请求(除非您使用 JavaScript 和 XMLHttpRequest 进行请求)。
How can another PHP (or ASP) page can read the data which was sent to it by another page?
对于本地存储,则不能。所有其他数据都可以通过服务器环境获得(例如,PHP 中的 $_POST
、 $_GET
和 $_COOKIE
)。
关于php - POST 和 GET 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7125700/