Note that there are some explanatory texts on larger screens.

plurals
  1. POAJAX innerHTML PHP array and location not working?
    text
    copied!<p>I am making a code where all comments in a database are echoed out with the help of AJAX. Right now I have two problems. </p> <ol> <li><p>Location is not working. Here is my code for opening the xmlHttpRequest.</p> <pre><code>xmlHttp.open("GET", "location.href.split('/').pop();", true); </code></pre> <p>I get the "Not Found" error when I check if the status == 200. But when I use a filename I know is in the directory it works. I must use something like the above because I have a few set variables in the url which makes unique pages.</p></li> <li><p>The comments are not echoing out. Here is my</p></li> </ol> <p><strong>PHP</strong></p> <pre><code>&lt;?php $showcomment=mysql_query("SELECT * FROM `photosite`.`comments` WHERE `photo_id`='$photo_id'"); echo '&lt;response&gt;'; while($allcomments=mysql_fetch_array($showcomment)){ echo '&lt;div id="comment"&gt;&lt;/div&gt;'; } echo '&lt;/response&gt;'; ?&gt; </code></pre> <p><strong>Javascript</strong></p> <pre><code>function process(){ if(xmlHttp){ try{ xmlHttp.open("GET", "location.href.split('/').pop();", true); xmlHttp.onreadystatechange = handleServerResponse; xmlHttp.send(null); }catch(e){ alert( e.toString() ); } } } function handleServerResponse(){ comment = document.getElementById('comment'); if(xmlHttp.readyState==4){ if(xmlHttp.status==200){ try { comment.innerHTML += "'.$allcomments['firstname'].' '.$allcomments['surname'].' '.$allcomments['comment'].'&lt;br&gt;"; }catch(e){ alert( e.toString() ); } else { alert(xmlHttp.statusText ); } } } } </code></pre> <p>On the innerHTML all I did was echo out what I had echoed without AJAX. It showed up on the page but as what is is. How do I get it to recognize they are PHP variables? Once they are echoed out on the PHP page shouldn't they become variables?</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