Trigger jquery script from PHP



I am trying to do the following:


1: Load an XML file (with a list devices that has a static name, and a changing value and note) - this works


2: Load the XML (t=0) into varaiables for easy use in the HTML - this works


3: Load XML again (t=200ms) - this works (I think)


4: Check if any values have changed between the two XML's


5: If TRUE then update one or more <DIV id=>


Task 1: I guess I need to have the loadxml script run again whenever it is done or say every 200 ms Task 2: I need to write and call a script that can update the <DIV id=>


I have made my code with only two parameters for easy understanding and put in comments where I guess I need to have something.


If this is a crazy overall architecture, please give me a direction to look to.



<?php

loadxml() ;

function loadxml() {
$feed_url = "demoxml.xml";
$xml = file_get_contents($feed_url);
$array = json_decode(json_encode((array)simplexml_load_string($xml)),1);

for ($id=1; $id<=157; $id++) {

//dynamic
$generation='new';
$hs3device_note[$id][$generation]= $array['device'][$id]['@attributes']['note'] ;
if ($hs3device_note[$id]['current'] != $hs3device_note[$id]['new']) { ;
$hs3device_note[$id]['current'] = $hs3device_note[$id]['new'] ;
//CALL SCRIPT (like ReplaceContentInContainer) TO UPDATE <DIV id = $id> WITH CONTENT $hs3device_note[$id]['new'])
} ;
$hs3device_value[$id][$generation]= $array['device'][$id]['@attributes']['value'] ;
if ($hs3device_value[$id]['current'] != $hs3device_value[$id]['new']) { ;
$hs3device_value[$id]['current'] = $hs3device_value[$id]['new'] ;
//CALL SCRIPT (like ReplaceContentInContainer) TO UPDATE <DIV id = $id> WITH CONTENT $hs3device_note[$id]['new'])
} ;

}
//MAKE loadxml() call it self or restart in 200 ms
} ;

<script type='text/javascript' src='jquery-1.7.2.js'>
function ReplaceContentInContainer() {
var container = document.getElementById(id);
container.innerHTML = content;
}
</script>

<DIV id="hs3device_note[34]['current']">...</DIV>
<DIV id="hs3device_value[34]['current']">...</DIV>

No comments:

Post a Comment