0

need some help on this one...

I'm working with a live notification...

I'm using this code to achieve this and its working fine:

function loadlinkAlert(){
$('#footer_main').load('./includes/userAlert.php',function () {
     $(this).unwrap();
});}

 var callnotification = function(){
 $.sticky('New Messae From: ');
 }
 setInterval(callnotification,4000);

but how can i put the data from userAlert.php to $.sticky('New Message From:'); next to "New Message From:"..

Thanks in advance..

Ryewell
  • 49
  • 1
  • 6
  • http://stackoverflow.com/questions/23740548/how-to-pass-variables-and-data-from-php-to-javascript.. Have a look.. –  Jan 11 '16 at 03:43

1 Answers1

0

You can just call your function with the data you get from your ajax call:

function loadlinkAlert(){
    $('#footer_main').load('./includes/userAlert.php',function(responseTxt, statusTxt, xhr) {
        $(this).unwrap();
        // responseTxt will hold the response from your ajax request
        // parse this accordingly to extract the data you want
        callnotification(responseTxt);
    });
}

// Give a parameter to say who the message is from
var callnotification = function(data){
    $.sticky('New Messae From: ' + data);
}
Nick Zuber
  • 5,467
  • 3
  • 24
  • 48
  • thanks sir.. but the code cat get my data: here my useralert.php: $readdata = file("../logs/alert.txt"); for ($i=0; $i <= count($readdata) - 1; $i++) { if ($readdata[$i] != "") { $userAlert = $readdata[$i]; } } – Ryewell Jan 11 '16 at 03:10
  • the result is: New Messae From: undefined – Ryewell Jan 11 '16 at 03:13
  • @Ryewell `responseTxt` holds the output from your `ajax` request. If your information is not being returned correctly the error lies within that file – Nick Zuber Jan 11 '16 at 03:15