I want to transfer a data from one webpage to another page. But I don't want to use the <form method="post">
tag because there are no forms in my webpage. Just some sensitive data is there which needs to be transferred to other page.
Please answer the following questions:
- What are the ways to transfer data from one page to another?
- What are the ways to transfer data from one page to another without using
<form>
tag in HTML? - H开发者_运维问答ow can another PHP (or ASP) page can read the data which was sent to it by another page?
I don't want to use the
<form method="post">
tag because there are no forms in my webpage
That is not a good reason to avoid using a form. You can add one.
What are the ways to transfer data from one page to another?
- Through the URI (in a query string)
- As part of the request body (a POST request)
- Via cookies (which you can set with JS)
- Via various local storage systems
Use a query string if the data needs to be bookmarkable. Use a POST request (with a form) if it makes changes on the server (e.g. adds or edits a database entry). Use a cookie (preferably set via HTTP after using methods 1 or 2) if the data needs to persist throughout the site. Use local storage for web applications that need to function offline.
What are the ways to transfer data from one page to another without using tag in HTML?
As above, but discount post requests (unless you make them using JavaScript and XMLHttpRequest).
How can another PHP (or ASP) page can read the data which was sent to it by another page?
With local storage, it can't. All the other data is available through the server environment ($_POST
, $_GET
and $_COOKIE
in PHP, for example).
You could use a hidden input i.e.
<input name="secret" type="hidden" value="superSecretData" />
You could create a random element which contains the data i.e.
<div style="display: none">SuperSecretData</div>
3a. In the case of the former in php it would just be a matter of accessing $_POST['secret']
3b. In the case of the later you would need to use javascript of something of that sort to take the random element and send it along with the page.
Hope this helps
1.) EasyXDM using postMessage if available, hash tags, or flash
2.) same as 1
3.) again you can use EasyXDM
if you open the other page with window.open or similar, or iframes
精彩评论