通过PHP和Ajax jQuery从TextArea中呼应短信

发布于 2025-02-10 12:57:43 字数 800 浏览 1 评论 0原文

HTML:

   <div class="mb-3">
       <label for="comment" class="form-label">Comments</label>
       <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
   </div>

JavaScript:

let comment = $('textarea.msg').val()
alert(comment);

然后是PHP:

echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';

在这里,Firefox Inspect的网络选项卡中的“响应”选项卡在PHP中没有显示回声命令。我不确定为什么未显示textarea输入hi因此未插入。

即使对于评论变量的JavaScript警报,我也会得到:

”在此处输入图像描述”

HTML:

   <div class="mb-3">
       <label for="comment" class="form-label">Comments</label>
       <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
   </div>

javascript:

let comment = $('textarea.msg').val()
alert(comment);

and then PHP:

echo $_POST['comment'];
echo isset($_POST['comment']);
echo trim($_POST['comment']) != '';

Here, the Response tab in Network tab of Firefox Inspect shows nothing for the echo commands in PHP. I am not sure why the textarea input hi is not shown hence not inserted.

Even for the javascript alert of comment variable, I get this:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

不回头走下去 2025-02-17 12:57:43
 let comment = $('#comment').val().trim();

克里斯·哈斯(Chris Haas)的学分。

 let comment = $('#comment').val().trim();

Credits to Chris Haas.

茶底世界 2025-02-17 12:57:43
<div class="mb-3">
   <label for="comment" class="form-label">Comments</label>
   <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>

ID在HTML中是唯一的,并且使用jQuery可以更轻松地定位所需的元素。对于课堂,我们使用$(。&lt; className&gt;)而对于ID时,我们使用$(#&lt; id_name&gt;)

您的案例>您的案例,$('#comment ').val()

<div class="mb-3">
   <label for="comment" class="form-label">Comments</label>
   <textarea class="form-control" id="comment" name="comment" rows="3"></textarea>
</div>

id is unique in the HTML and with jquery it would be easier to target the element you want. For class we use $(.<classNAME>) while for id we use $(#<id_Name>)

Your Case, $('#comment').val()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文