?
Solved

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

Posted on 2010-01-01
3
Medium Priority
?
683 Views
Last Modified: 2013-11-08
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

0
Comment
Question by:rpkhare
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 1500 total points
ID: 26158765
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
 
LVL 8

Author Closing Comment

by:rpkhare
ID: 31671757
Thanks
0
 
LVL 82

Expert Comment

by:hielo
ID: 27956910
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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month16 days, 2 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question