Note that there are some explanatory texts on larger screens.

plurals
  1. POAppending contents of a php file (html w/php) to a div
    text
    copied!<p>How do I append the contents of a php file (mix of html and php) into an existing div?</p> <p>I have this div defined which loads three different php files. But this is very slow because each php retrieves many items with http. I'd like to have the first php <code>&lt;?php require("readenglish.php"); ?&gt;</code> then load the others asynchronously afterwards. I tried a $.get() but that does not load the php content.</p> <p>Here is the div.</p> <pre><code>&lt;div id="readings"&gt; &lt;?php require("readenglish.php"); ?&gt; &lt;!-- ?php require("readfrench.php"); ? --&gt; &lt;!-- EDITED OUT DON'T WANT THIS --&gt; &lt;!-- ?php require("readspanish.php"); ? --&gt; &lt;!-- --&gt; &lt;/div&gt; </code></pre> <p>Here is the script that loads the php files.</p> <pre><code>&lt;!-- EDIT WANT THIS INSTEAD OF WHAT IS COMMENTED OUT ABOVE --&gt; &lt;script&gt; $(document).ready(function(){ $.get("readfrench.php",function(data){ $("#readings").append(data); },'html'); $.get("readspanish.php",function(data){ $("#readings").append(data); },'html'); }); &lt;/script&gt; </code></pre> <p>Here is a sample php file.</p> <pre><code>&lt;?php $todayfeast = date("Ymd"); $ctitlefe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&amp;type=reading_lt&amp;lang=AM&amp;content=FR'; $creadfe = 'http://feed.evangelizo.org/reader.php?date='.$todayfeast.'&amp;type=reading&amp;lang=AM&amp;content=FR'; if ( $curl_exists ) { curl_setopt($ch, CURLOPT_URL, $ctitlefe); $titlefe = curl_exec($ch); curl_setopt($ch, CURLOPT_URL, $creadfe); $readfe = curl_exec($ch); } ?&gt; &lt;div id="readf" class="tabbertab"&gt; &lt;h2&gt;First Reading&lt;/h2&gt; &lt;div id='titlefe' class='rtitle'&gt; &lt;?php echo $titlefe; ?&gt; &lt;/div&gt; &lt;div id='readfe' class='rtext'&gt; &lt;?php echo $readfe; ?&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>The php file loads the contents retrieved into variables which are passed to html elements. These elements must be appended to the div shown at the top.</p> <p>Is there a different way to call $.get()? Is there a different way to do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload