1

I am running a simple script to get data from mysql into select box but it doesn't fetch any data. below is the code :

<body>
Team :  <select id="teamname"> </select> <br />
Members : <select id="members"> </select>
</body>

Jquery :

$("document").ready(function(){
$.getJSON("ajax.php", function(data){
    $("#teamname").empty();
    $.each(data.result, function() {
        $("#teamname").append("<option>" + this('team_name') + "</option>");
    });
});

PHP

$result=array();
$getteams=mysql_query("select * from tbl_teams");
if(mysql_num_rows($getteams)){
    while($gotteams=mysql_fetch_array($getteams)){
        array_push($result,array('id' => $gotteams['team_id'],
                                 'name' => $gotteams['team_name']));
    }
    echo json_encode(array('result' => $result));
}

I tried everymeans and every other example available online but still doesn't work. Please help me.

2
  • Check for errors, check your console, check your logs. Commented Mar 1, 2015 at 18:24
  • Open firebug, see what is return in http request. Commented Mar 1, 2015 at 18:25

1 Answer 1

1

You have got column name as 'name' not 'team_name' in array ( 'name' => $gotteams['team_name'])

try

$.each(data.result, function() {
        $("#teamname").append("<option>" + this['name'] + "</option>");
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.