[英]How can an HTML page extract parameters passed through a form?
My question is should I convert two html pages to php pages, so the called page can access its POSTed parameters, or is there a way for a called html (.html extension) page to access posted parameters? 我的问题是我应该将两个html页面转换为php页面,以便被调用页面可以访问其POSTed参数,还是有办法让被调用的html(.html扩展名)页面访问已发布的参数?
I've been reading that because posted parameters are server-side there is no way for JavaScript to do this being client side. 我一直在读,因为发布的参数是服务器端的,所以JavaScript无法在客户端进行此操作。 I've seen nothing about one html page accessing parameters if that .html page was accessed via a POST.
如果通过POST访问.html页面,则我对任何一个html页面访问参数一无所知。
Here is my calling form. 这是我的电话表格。 The called form, needs access to TransDesc (below), which is a text field.
被调用的表单需要访问TransDesc(如下),它是一个文本字段。
<script type="text/javascript" language="JavaScript1.2">
// Check where we came from so that we can go to the right spot when the
// form gets posted from outside of our HTML tree.
var PostURL = '/event.html';
</script>
Enter a Donation Amount
<script type="text/javascript" language="JavaScript1.2">
document.write(
'<form name="InvGenPayDonation"
action="'+PostURL+'"
onsubmit="return validateForm();"
method=POST>');
</script>
<p> $ <input type='text' name='Amount' value="0.00">
</p>
<p>In honor of <span style="color: #FF0000">
<input type='text' name='TransDesc' id='TransDesc' value="" >
</p>
<input type="submit" value="Next"> <br /><br />
我认为,php是最简单的方法,而就语言而言,它很容易学习且非常直观。
您必须将它们转换为PHP或使用GET而不是POST,因为可以通过window.location.href
访问GET参数。
A static HTML file cannot access variables that have been POST'ed to it. 静态HTML文件无法访问已过POST的变量。 It can't even know they're there as they're sent to the server in the HTTP request, the server then deals with them and sends the HTML page in the HTTP response.
当它们通过HTTP请求发送到服务器时,甚至不知道它们在那,然后服务器处理它们并在HTTP响应中发送HTML页面。 They're 'consumed' before the page is even sent to the client.
在页面发送到客户端之前,它们已经被“消耗”了。
You could use GET and access them via JavaScript, or configure Apache to server .html files as PHP files instead though. 您可以使用GET并通过JavaScript访问它们,或者将Apache配置为将.html文件服务器作为PHP文件。
Yes, I would recommend converting the pages to php. 是的,我建议将页面转换为php。 If you are set on using HTML files you will have to edit your htaccess file to run HTML pages as php.
如果您准备使用HTML文件,则必须编辑htaccess文件以将HTML页面作为php运行。
You can always use ajax to retrieve and send post and get values. 您始终可以使用ajax来检索和发送帖子并获取值。
You can retrieve it with js by creating a php file and access those with ajax from your html files. 您可以通过创建一个php文件来使用js检索它,并从html文件中使用ajax访问这些文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.