从 POST 传递带有换行符的字符串时,文本区域未更新?
我的代码遇到了一些麻烦,我将其范围缩小并简化为以下两个部分:
index.html
<html>
<body>
<form name="form" method="post" action="upload.php" target="iframe">
<textarea id="text1" name="text1"></textarea>
<input type="submit" />
</form>
<textarea id="text2"></textarea>
<iframe name="iframe" id="iframe" style="display:none;" ></iframe>
</body>
</html>
upload.php:
<?php
$message= $_POST['text1'];
echo <<<_END
<script language="JavaScript" type="text/javascript">
var parDoc = window.parent.document;
parDoc.getElementById('text2').value = '$message';
</script>
_END;
?>
代码的总体目标上面是在text2中呈现我从text1提交的内容。这适用于 text1 中包含换行符的消息。当尝试提交带有换行符的消息时,text2 不会更新。我似乎无法追踪错误,而且我真的陷入了这个错误的心理困境。有什么想法吗?同样,这是我的整体代码的简化版本。我将错误缩小到这个问题。
I'm running into some troubles with my code, which I narrowed down and simplified in the two following segments:
index.html
<html>
<body>
<form name="form" method="post" action="upload.php" target="iframe">
<textarea id="text1" name="text1"></textarea>
<input type="submit" />
</form>
<textarea id="text2"></textarea>
<iframe name="iframe" id="iframe" style="display:none;" ></iframe>
</body>
</html>
upload.php:
<?php
$message= $_POST['text1'];
echo <<<_END
<script language="JavaScript" type="text/javascript">
var parDoc = window.parent.document;
parDoc.getElementById('text2').value = '$message';
</script>
_END;
?>
The overall goal of the code above is to present in text2, what I submitted from text1. This works with the exception of a message in text1 that contains newlines. When attempting to submit a message with newlines text2 is not updated. I can't seem to trace the error and I'm really stuck in a mental rut with this one. Any ideas? Again, this is a simplified version of my overall code. I whittled the error down to this problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 upload.php 中尝试一下
Try this in upload.php