Hello everyone, I am trying to write a simple web application where I have a mySQL table. I am using drop down menus to select options on how to filer the table.... i.e. select the subject, filter the table for just that subject and continue on. Anyways I'm trying to use AJAX. I went to w3schools and literally copied and pasted the code... it seems to be working for them but my xmlhttp.onreadystatechange=function() does not want to get called or go through. I was wondering if someone could help me because I've been at it for a couple hours with no luck.

$script = "<script language='Javascript' type='text/javascript'>
function loadTopics()
{
var xmlhttp;
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById('Topics').innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open('GET','loadTopics.php',true);

xmlhttp.send();


}
</script>";

echo $script;

I posted a number of different alert messages and know that it is where the onstatereadychange=function the error must be occurring. Or at least, as far as I have deduced...

The HTML code looks something like this (so far).

<div id='Topics'> <select> </select> </div>

Thanks in advance.

OK. I got it figured out. To give a little bit more of a background I am writing a little application for my wordpress blog. I am using a php-plugin so I can write php into a page... which in this case is just a <?php include....?>. That was issue #1.

When I looked at the source code the && was actually being outputted as some funky html code for ampersands like &0#02; or something. Fix #1 was replaced the if-statement to two nested if-statements.

Next, I realized I was running on a Linux Server which does not support Ajax. That was issue #2.

Issue #3 was the 'loadTopics.php' requires a '/'.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.