i have a php page that redirects (if successful) to another php page like this:
header('Location: completed.php?message=Successful operation. Data inserted for user: ' . $login->get_username() . ' . See home page for infos.');
Now in completed.php i have a div that echoes the received message:
<div id="msg">
<?php echo $_GET['message']; ?>
</div>
I’m using the ‘Toastmessage-plugin’ : here.. , but i’m unable to display the $_GET in to the text of Toastmessage ..
I’m using this code :
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="js/jquery.toastmessage.js" type="text/javascript"></script>
<link href="styles/jquery.toastmessage.css" rel="stylesheet" type="text/css" />
...
<script type="text/javascript">
function showStickyNoticeToast() {
$().toastmessage('showToast', {
text: $('#msg').val(),
sticky: true,
position: 'bottom-left',
type: 'notice',
closeText: '',
close: function () { console.log("toast is closed ..."); }
});
}
</script>
I’ve searched a lot , also for DOM Events and other events but i don’t know what step take… maybe when the JQ function is loaded the div ‘msg’ has not yet received GET data …? so how i update his value ?
The page i’ve read :
this and this.
I also tried with ajax but i’m less experienced in that language..
please help… 🙂 Thanks
EDIT @charlietfl
Ajax : i’ve made a lot of tries… i can’t find the code anymore!
Basically i call a php file with this code (take this as pseudocode):
<script type="text/javascript>
<!--
$('#choose').change(function(event) {
$.get('messages.php', { selected: $('#msg').val() },
function(data) {
$('#update').html(data); // other div wher store data
}
);
});
</script>
….
<?php
$alfa = isset($_GET['message']) ? $_GET['message'] : 'nothing';
echo $alfa;
?>
Got it: you use
$("#msg").val()butDIVtags have not a “value”.Use
$("#msg").text()(for plain-text)or
$("#msg").html()to include also some HTML you may have in your code (pretty sure you need the first option).
Use
.val()only with “valued” tags like<input>(works also with<textarea>).See also: http://api.jquery.com/val/