Guy1984
Guy1984

Reputation: 23

Call php echo from jQuery?

I have a jQuery script in my header that calls a php file.

The php file contains data pulled from a remote xspf file, and the output presented in jQuery for refresh purpose. i have 2 echo rules, one for title and one for listeners. right now jQuery calls the file itself which makes the output appear together on a single line. how can i make jQuery present these echoes separately so i can control their design (CSS)?

PHP:

<?php
header("Expires: Tue, 03 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

$xml = simplexml_load_file("http://mysitehere:8000/live.xspf"); 

foreach ($xml->trackList->track as $data) { 
    $radio = $data->location;
    $song  = $data->title;  
    $info = $data->listeners;   
}
echo $song;
echo $info;
?> 

jQuery:

<script language="javascript">
jQuery(document).ready(function(){
    //Carga al comienzo
    jQuery('#salida').load('reader.php');   
    setInterval(function() {        
        jQuery('#salida').load('reader.php');   
    }, 2000);
})
</script>

<div id=salida> </div>

Upvotes: 1

Views: 362

Answers (1)

Patrick Evans
Patrick Evans

Reputation: 42736

Put the echoed info into separate elements

echo '<div class="Song">'.$song.'</div>';
echo '<div class="Info">'.$info.'</div>';

then setup classes in your css for Song, Info (or whatever names you want to give them)

Upvotes: 2

Related Questions