aneeb Posted November 19, 2012 Share Posted November 19, 2012 Hey everyone! i am creating a dynamic drop down menu in html, but the values are not coming in the drop down, it shows an empty menu. I am calling the PHP file which is echoing JSON of the data. here is the Javascript code.. $(function(){var serviceURL = "http://localhost/mano-2/";var get = ''; get = 'echo_cat.php'; var items=""; $.getJSON(serviceURL + get , function(data){ $.each(data,function(index,item) { items = items + "<option value='"+item.entity_id+"'>"+item.name+"</option>" ; }); $("#a1_title").html(items); });}); the JSON is like this {"items":[{"entity_id":"1","name":"Root Catalog"},{"entity_id":"2","name":"Default Category"}]} the HTML code is like this <select id="a1_title"> <option>Default</option></select> Please help me.. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 19, 2012 Share Posted November 19, 2012 You should check for Javascript errors, but it looks like you want to loop over data.items instead of just data. There's only 1 item in data, which is the "items" array. Link to comment Share on other sites More sharing options...
aneeb Posted November 19, 2012 Author Share Posted November 19, 2012 In error log it is saying that $ is not defined... Link to comment Share on other sites More sharing options...
Ingolme Posted November 19, 2012 Share Posted November 19, 2012 Maybe you haven't included jQuery or whichever library is using the $ symbol. Link to comment Share on other sites More sharing options...
aneeb Posted November 20, 2012 Author Share Posted November 20, 2012 i have included the jQuery, but still the data is not coming in the drop down. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now