1

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>
4
  • 1
    Encode your data as JSON, retrieve it with jQuery and process it accordingly (create elements, etc). Right now you are simply taking the response and simply dump it on the page. If you structure the response, you will be able to process it properly with JavaScript. Commented Aug 20, 2012 at 12:08
  • can you kindly direct me to a good JSON tutorial to achieve this? im not familiar with JSON.. Commented Aug 20, 2012 at 12:11
  • Just search for it here on SO or the web. There are many, many resources. That said, using JSON is not the only way of course how you could solve this problem, but in the long you will be more flexible. It also depends on what kind of data you have though. Commented Aug 20, 2012 at 12:16
  • Thanx Felix,i will def' follow your advice and learn JSON. Commented Aug 20, 2012 at 12:24

1 Answer 1

2

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.