在php函数中嵌入jquery弹出窗口
嗨,我有一个jquery弹出脚本,我正试图在php函数中调用它 调用函数的脚本是:在php函数中嵌入jquery弹出窗口,php,jquery,popup,Php,Jquery,Popup,嗨,我有一个jquery弹出脚本,我正试图在php函数中调用它 调用函数的脚本是: <link rel='stylesheet' href='css/sweetalert.css'> <script src='js/sweetalert-dev.js'></script> <script src='https://code.jquery.com/jquery-2.1.3.min.js'></script> <?php incl
<link rel='stylesheet' href='css/sweetalert.css'>
<script src='js/sweetalert-dev.js'></script>
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
<?php
include('functions/notification.php');
$notification_message = "There is a problem loading Smart Telecom at the moment.";
notify($notification_message);
?>
以及notification.php中的函数调用:
<?php
function notify($message)
{
$pop.= "<script>sweetAlert('". $message ."', 'Our Sincere apologies.', 'error');</script>";
echo $pop;
}
好,请按照以下步骤确保代码正常工作,然后检查pop问题:
删除函数中的所有数据,如下所示:
<?php
function notify($message) {
echo $message;
} //output: data passed to $message variable should be displayed?>
如果echo$消息有效,则
<link rel='stylesheet' href='css/sweetalert.css'>
<!-- You must always place the jQuery first and then call functions or it will not work -->
<script src='https://code.jquery.com/jquery-2.1.3.min.js'></script>
<script src='js/sweetalert-dev.js'></script>
<?php
function notify($message) {
$pop = "<script>sweetAlert('$message', 'Our Sincere apologies.', 'error');</script>";//refer link: http://stackoverflow.com/questions/10512452/php-using-a-variable-inside-a-double-quotes
echo $pop;
}?>
这是因为您在notify
函数中使用=
,=
意味着向现有变量添加一些内容,但由于该变量在$pop.=
行之前不存在,它会抛出未定义的变量消息。-从$pop.=
中删除点,您应该被设置。扩展@Epodax的注释,只需将$pop.=
更改为$pop=
,当我不进行连接时,弹出窗口不会显示try changing variable name。更改变量名称不起作用。它只在我放置连接时显示,这毫无意义。您更改了什么,为什么?只有代码的答案很少能为OP和未来的访问者提供更多的洞察力,一个好的答案可以解释OP做错了什么/你做了什么改变使它工作。没有运气。仍然没有显示popup@user5898266,请参阅此以了解具有不同变化的变量: