javascript - Change innerHTML from an external php file -
i've got script in html file runs php file every 30 seconds. php file intended change div's innerhtml. don't seem find way replace it.
i using load() there several divs want keep updating every 30 seconds , don't want make server requests. i'm looking 1 php , change innerhtml in several divs
this i've got:
html:
<script type="text/javascript"> $(document).ready(function () { $.get('php.php'); }); setinterval(function(){ $.get('php.php'); }, 30000); </script> <div id="foo"></div> php.php:
document.getelementbyid("foo").innerhtml = '<?php // php code ?>'; i think problem i'm not being able element parent html file. don't know how solve this... suggestions more aprecciated!
you reinventing jquery's load()
function fetchcontent() { $("#foo").load('php.php'); window.settimeout(fetchcontent, 30000); } $(fetchcontent); the server should return html content want display.
edit
since comment different original question.
function fetchcontent() { $("#foo").get('php.php', function(data) { var html = $("<div/>").html(data); $("#foo").html( html.find("#section1").html() ); $("#bar").html( html.find("#section2").html() ); $("#asd").html( html.find("#section3").html() ); window.settimeout(fetchcontent, 30000); }); } $(fetchcontent); you want add onerror handler , might want set no cache option ajax calls.
Comments
Post a Comment