【问题标题】:Trigger JS Function on HTML Page from PHP File从 PHP 文件触发 HTML 页面上的 JS 函数
【发布时间】:2019-06-18 19:36:52
【问题描述】:

我的问题如下:

我有两个文件。我们称它们为 form.html 和 handler.php

如您所料,html 文件是一个电子邮件表单,而 php 文件用于发送它。

现在我想在邮件发送成功与否时从 php 文件中触发 html 文件上的 BS4 警报。

<div class="alert alert-danger alert-dismissible fade show" role="alert">
     <strong>Whoops!</strong>Something went wrong there.. Please try again!
     <button type="button" class="close" data-dismiss="alert" aria-label="Close">
             <span aria-hidden="true">&times;</span>
     </button>
</div>

<div class="alert alert-success alert-dismissible fade show" role="alert">
     <strong>Success!</strong>Mail successfully delivered. I will be in touch with you shortly!
     <button type="button" class="close" data-dismiss="alert" aria-label="Close">
             <span aria-hidden="true">&times;</span>
     </button>
</div>

稍后应该触发警报的 php 代码部分正在链接到定义的页面。

if($mail_senden){
    header("Location: ".$url_ok); //Fehler beim Senden
    exit();
} else{
    header("Location: ".$url_fehler); //Fehler beim Senden
    exit();
}

有什么想法吗?

也许我应该提到我熟悉引导程序,但我在 js 和 php 方面的知识非常有限(#scriptkidlifestyle)

【问题讨论】:

  • 您可以将 JS 代码注入您正在服务的页面中,那么您的问题是什么?
  • 我该怎么做呢?正如我所写,我对 JS 完全一无所知
  • 好的,谢谢!我去看看。

标签: javascript php html function call


【解决方案1】:

如果您只是想显示警报:

<script>
if (mail_sent) {
    alert("Mail sent !");
    }

else{
    alert("Mail not sent");
}
</script>

【讨论】:

  • 不,这不是我想做的,因为 php 文件和 HTML 是 2 个文件,我想在 HTML 页面上显示警报。
  • Hem... 是的,我猜你的 PHP 文件和你的 HTML 文件是 2 个文件。但是你可以包含一个带有 的 PHP 文件
  • 是的,但那会做什么?我猜你没有得到正确的问题。我想使用 js.. 从单独的 php 文件中触发 HTML 文件的警报
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-18
  • 1970-01-01
  • 2022-01-19
相关资源
最近更新 更多