gpt4 book ai didi

PHP Post 调用不返回变量

转载 作者:行者123 更新时间:2023-11-28 11:25:32 26 4
gpt4 key购买 nike

我有一个隐藏的输入字段,我使用 jquery 填充一些任意值,这样:

function foo() {
// Obtains the contents of a div within the current page
var $elem = $("#something").html();
// Places the contents of the div into a hidden input field
$("#hidden").val($elem);
}

在调试过程中,我可以看到 elem 变量从所需的 div 中获取 html,但看不到该变量是否传递到隐藏输入字段值。

我有一个表格:

<form method="POST" action="file.php" target="_blank">
<input id="hidden" type="hidden" value=""/>
<input type="submit" onmouseover="foo()" value="Download"/>
</form>

提交后执行 file.php:

<?php
$html = $_POST["hidden"];
echo $html;
?>

echo 调用没有返回任何内容,我得到的只是一个空白页。我想知道为什么隐藏输入字段的值没有被更改,或者为什么在 POST 调用期间没有传递它。

一些进一步的实验表明,即使我将隐藏字段的值设置为一些随机值:

<input id="hidden" type="hidden" value="Some Value"/> 

在PHP文件执行过程中仍然没有获取到。 echo 调用不返回任何内容。我获取这个隐藏输入字段的值有什么问题?我很少使用 PHP,但过去在 POST 提交时从表单获取值没有遇到问题。

最佳答案

您需要为输入字段指定一个名称,以便在 php 中使用 $_POST 访问它

<input id="hidden" name="hidden" type="hidden" value=""/>

关于PHP Post 调用不返回变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14187871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com