简体   繁体   English

HTML页面如何提取通过表单传递的参数?

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

相关问题 如何通过PHP获取page.html#PARAMETERS? - How can i get the page.html#PARAMETERS through PHP? HTML表格可以通过表单传递并通过post获得值吗? - Can an HTML table be passed in form and get the value through post? 如何通过URL传递作为参数传递的PHP值并将其显示在HTML页面中以传递给另一个PHP文件 - How to pass php value which is passed as a parameter through url and displaying it in html page to be passed to another php file 无法获取传递给页面回调的参数 - Can't get parameters passed to page callback 如何访问传递到下一页的参数 - How to access parameters that were passed to next page 如何保护传递给另一个页面的查询字符串或参数 - How to protect querystring or parameters passed to another page 如何从HTML页面提取链接? - How can I extract the links from a page of HTML? 如何在PHP脚本中访问使用jQuery.ajax()从HTML页面传递的表单数据的各个值? - How to access individual values of form data, passed from an HTML page with jQuery.ajax(), inside a PHP script? 如何在页面上显示不同的联系方式,具体取决于链接到该页面的页面? (联系表7) - How can I show a different contact form on a page depending which page linked through to that page? (Contact Form 7) 如何提取通过onclick函数事件传递的值? - How to extract the value passed in through onclick function event?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM