Hi I have a jquery popup script I am trying to call in a php function.
The script calling the function is:
<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);
?>
and the function call in notification.php:
<?php
function notify($message)
{
$pop.= "<script>sweetAlert('". $message ."', 'Our Sincere apologies.', 'error');</script>";
echo $pop;
}
?>
As it is, the pop up will display with an error about undefined variable $pop. If I try to disable error notifications, the popup doesn't display. if I do it without the concatenation, the popup also doesn't display.
Where am I going wrong?
UPDATE - SOLVED:
Got it to work. echoed "nbsp;", just before echoing $pop
1 Answer 1
Ok so follow these steps to ensure the code is working, then check the pop issue:
Delete all data in the function to look like below:
<?php function notify($message) { echo $message; } //output: data passed to $message variable should be displayed?>if echo $message works then
<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; }?>
.=in yournotifyfunction,.=means to add something to existing variable, but since the variable doesn't exist before your$pop .=line, it throws that undefined variable message. - Remove the dot from the$pop .=and you should be set.$pop.=to$pop =