Question edited:
I'm working on an alternative to iframes because WP.org balks at them and tends to reject plugins that have them (I know this from experience) So, here's the code I have to try to replace an iframe:
add_action('wp_ajax_myAction', array($this, 'myAction_ajax_handler'));
public function myAction_ajax_handler() {
echo time();
wp_die();
}
When the admin page is displayed, I have this:
echo '<body onLoad="loadDoc();">';
echo '<div id=myDiv></div>';
?>
<script>
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("myDiv").innerHTML = this.responseText;
}
};
xhttp.open("GET", ajaxurl + "?action=myAction", true);
xhttp.send();
setTimeout("loadDoc()", 1000);
}
</script>
<?php
It works.
Here's my questions.
Is this the proper way to do this?
Is there a better way to do this instead of polling with setTimeout?
Thanks!