I have all the correct files linked to use bootstrap notify included in my main index file this Request.php page is loaded into my main navigation using angularjs results resides in the index file and that is where i wish the notification to appear but when I have the script in place it wont run!
The javascript function:
function SubmitFormRequest() {
var habbo = $("#name").val();
var message = $("#message").val();
$.post("pages/request_submit.php", { name: name, message: message },
function(data) {
$('#results').html(data);
$('#myForm')[0].reset();
});
}
The php script:
<?php
require_once( "../staff/staff/_inc/glob.php" );
$message = $_POST['message'];
$habbo = $_POST['habbo'];
$db->query( "INSERT INTO `requests`(`id`, `habbo`, `message`, `ip`) VALUES (NULL, '{$habbo}', '{$message}', '1')");
?>
<script>
$.notify("Hello World");
</script>
$('#results').html(data);
This line will attach the code as text into the html document, but won't execute the JavaScript.
You should use eval to execute JavaScript
data = data.replace(/<\/?script>/g, '');
eval(data);
or append a script node into HTML DOM.
data = data.replace(/<\/?script>/g, '');
var script = document.createElement('script');
script.innerHTML = data;
$('head').append(script);