JQuery/JSON code not able to get data to fill DropDown.

I want to populate a DropDown control using JQuery dynamically. It is not fetching data from the .php file. Below is the JQuery code and the .php file code.

The file "dbaccess.php" that is referred in the .php file, just contains a mysql_query function and it returns the resultset.

[Code: JQuery]

<script type="text/javascript">
$(document).ready(function(){
    //$('#inDistrict').sSelect();
    $("#inDistrict").change(function(){
    $.getJSON("filldistricts.php",{id: $(this).val(), ajax: 'true'}, function(j){
      var options = '';
	  for (var i = 0; i < j.length; i++) {
      	options.push( '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>' );
		$('#inDistrict').html(options.join(''));
      }
    })
  })
})
</script>

[Code: filldistricts.php]

<?php
	require_once("../Lib/dbaccess.php");
	$query = "SELECT districtid FROM districtmaster";
	try
	{
		echo "<script type='text/javascript'>alert('file');</script>";
		$result = dbaccess::GetRows($query);
		echo json_encode($result);
	}
	catch(exception $ex)
	{
		echo "<script type='text/javascript'>alert('".$ex."');</script>";
	}
?>

Open in new window

LVL 8
rpkhareAsked:
Who is Participating?
 
hieloCommented:
comment out:
echo "<script type='text/javascript'>alert('file');</script>";

by leaving that there you are no longer sending a valid json string. The whole output of your script must be json, not just "parts" of it.
0
 
rpkhareAuthor Commented:
Thanks
0
 
hieloCommented:
rpkhare
please consider re-grading this post.

Refer to:
http://www.experts-exchange.com/help.jsp#hs=29&hi=403

You can post a request in the Community Support zone to have the problem re-opened for grading.

Regards,
Hielo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.