0

I got a simple AJAX demo code from internet which fills one select listbox dynamically with values from database. It contains a html file with AJAX code embedded in it and a PHP file.

The problem is this code works fine in IE, Chrome, FireFox4 but its not works in FireFox3. Please any one explain this and tell me the solution. The code is as follows for reference

The database schema for city table is as follows

id tinyint(4) primary key not null
city varchar(50)
countryid tinyint(4)

HTML File

<html>
<head>
<script type="text/javascript">
function getCity(strURL)
{         
alert("inside getCity function");
//var req = getXMLHTTP(); // function to get xmlhttp object

if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
    //xmlhttp=new XMLHttpRequest();
    req=new XMLHttpRequest();
}
else
{// code for IE6, IE5
    //xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    req=new ActiveXObject("Microsoft.XMLHTTP");
}

if (req)
{
    req.onreadystatechange = function()
    {
        if (req.readyState == 4) { //data is retrieved from server
            if (req.status == 200) { // which reprents ok status                    
                document.getElementById('citydiv').innerHTML=req.responseText;
            }
            else
            { 
                alert("There was a problem while using XMLHTTP:\n");
            }
        }            
    }        
    //alert(srtURL);
    var sURL="findcity.php?country="+strURL;
    req.open("GET", sURL, true); //open url using get method
    req.send();
}
}
</script>
</head>
<body>
<form method="post" action="" name="form1">
Country : <select name="country" onChange="getCity(this.value)">
<option value="">Select Country</option>
<option value="1">india</option>
<option value="2">usa</option>
</select>
<br />City : <div id="citydiv">
<select name="select">
<option>Select City</option>
 </select>
</div>
</form>
</body>
</html>

PHP file

<? 
echo $_GET['country'];
echo "<br>";
$country=intval($_GET['country']);
echo $country;
echo "<br>";
$link = mysql_connect('localhost', 'root', 'mark'); //change the configuration if required
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('querytest'); //change this if required
$query="select city from city where countryid=$country";
echo "<br>";
echo $query;
echo "<br>";
$result=mysql_query($query);?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
   <option value><?=$row['city']?></option>
<? } ?>
</select>

Please guide me friends to make this code working in FireFox 3

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Param-Ganak
  • 5,787
  • 17
  • 50
  • 62
  • What does the javascript console report to you, as far as errors? – J. Steen Jul 27 '11 at 08:30
  • Could you do some debugging? What doesnt work, what error messages do you see? – TJHeuvel Jul 27 '11 at 08:30
  • @ J.Steen Its not giving any error message but its not filling the city select box dynamically from database as on the selection of country – Param-Ganak Jul 27 '11 at 08:36
  • Its gives following exception " Error: uncaught exception: [Exception... "Not enough arguments [nsIXMLHttpRequest.send]" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://192.168.1.122/testhtml/test.html :: getCity :: line 37" data: no]" – Param-Ganak Jul 27 '11 at 08:46

1 Answers1

0

Change

req.send();

to

req.send(null);
chrislondon
  • 12,487
  • 5
  • 26
  • 65