views:

72

answers:

3

Hi i am developing a web app.I am retrieving options of the select box from database and i want to write these records to selectbox.My page structure is like that:

main.php=>there is a selectbox in this page <select id="my_select"></select>

retrieve_data.php=>i make a ajax call to this page and this page gets the phone numbers from the db and responses the data to main.php.

i get the data from the retrieve_data.php but when wanted to write these response to selectbox it fails.only empty selectbox appears.

My response like his:<option>blabla</option>......

and i wrote it like this: $("#my_select").html(response);

i alerted the response before writing in to selectbox and it alerts right options but when i tried to write them into selectbox it fails.can anyone help me thanks for advance...

A: 

Using the jQuery .html() function is correct, but I need to see more code to understand your problem. Particularly what is response equal to? It looks like, as others have mentioned, that the response variable is coming back as JSON rather than a simple string. Can you post what it looks like when you do an alert(response);?

jordanstephens
function get_setting_numbers(type){ var type=type; $.ajax({ type: 'POST', url: 'functions/get_setting_numbers.php', data:'type='+type, dataType:'json', success: function(JSON){ if(JSON.data.result=="true"){ alert(JSON.data.response); $("#first_rule").html(JSON.data.response); }else{ open_message(JSON.data.response,0); } } }); }
cubuzoa
you should post additional content relative to your question in the body of the question itself. with proper spacing, etc... to make it readable to those trying to help you. just edit the question and add the new content.
jordanstephens
+2  A: 

I'm going to go out on a limb and assume that the response is coming back in the form of a single member array. That would explain why the alert() shows the response, but it is not being inserted.

So, try this:

$("#my_select").html( response.join('') );

EDIT:

<option> tags in output were misspelled.

patrick dw
hi patrick my response type is JSON and i used your code :$("#my_select").html((JSON.data.resonse).join('')); but it didnt work
cubuzoa
A: 

Could be this bug if you are using Explorer.

Tgr
i am using firefox
cubuzoa