Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ajax for dynamic options does not work after server switch

Status
Not open for further replies.

electricphp

Programmer
Feb 20, 2008
71
0
0
US
I had this script that was working fine on the development server and when I moved it to the new server it stopped working. I don't even know how to begin to debug this.

Normally when you select a county the town1 select box gets populated, but on the new server when you select a county nothing happens.


Code:
<script type="text/javascript" charset="utf-8">
$(function(){
$("select#county1").change(function(){
$.getJSON("data1.php",{act: 'getTown', county1: $(this).val()}, function(j){
var options = '';
for (var i = 0; i < j.length; i++) {
options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
}
$("select#town1").php(options);
})
})
})
</script>


										  <option selected="selected">Select County</option>
										  <?php do { ?>
                              <option>
                              <?= $row_stat['county']; ?>
                              </option>
                              <?php } while ($row_stat= mysql_fetch_assoc($stat)); ?>
                          </select>
    
 <select name="town1" id="town1"></select>

data1.php:

Code:
include("include/init.php");

if ($_GET['act']=='getTown') {
$query_state = sprintf("SELECT * FROM zip1 WHERE county = '%s' GROUP BY city ORDER BY city ASC", $_GET['county1']);
$state = mysql_query($query_state) or die(mysql_error() ." " .$query_state);
$row_state = mysql_fetch_assoc($state);
do {
$options[] = "{optionValue:'".$row_state['city']."', optionDisplay: '".phpentities(trim($row_state['city'])) ."'}";
} while ($row_state = mysql_fetch_assoc($state));
$theOptions = implode(",", $options);
$theOptions = "[".$theOptions."]";
echo $theOptions;
}
?>

please help
 
I don't even know how to begin to debug this.

If you visit the URL manually (i.e. not via AJAX, but by typing it in to the URL bar), do you get the expected response?

That, at very least, will tell you whether it's an AJAX problem or a PHP problem.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
I would, if you haven't already, recommend installing FireBug for FireFox, as it lets you see easily Params, Headers, Post data and response data from all AJAX calls.

Scott Prelewicz
Web Developer
COMAND Solutions
 
If it just stopped working, and no error messages are present, I would suggest that a) required files are missing in the production environment, b) your database connection script may be the fault, or c) something else. :p

HTH

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top