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

Posted on 2010-01-01
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">




    $.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>' );







[Code: filldistricts.php]



	$query = "SELECT districtid FROM districtmaster";



		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

Question by:rpkhare
    LVL 82

    Accepted Solution

    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.
    LVL 8

    Author Closing Comment

    LVL 82

    Expert Comment

    please consider re-grading this post.

    Refer to:

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    Suggested Solutions

    How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
    Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now