Reputation: 9646
I'm trying to load a drop down box with data from the server.
The data from the server is like this: <select><option>...</option></select>
I have something like this right now but i don't know how to load the html from the server..?
$.getJSON("myurl", function(result) {
//how do I load html from the server to the dropdown element
});
Upvotes: 0
Views: 81
Reputation: 219
$.getJSON() sets the dataType as JSON, you should set dataType: 'html' using $.ajax instead.
Something like this:
$.ajax({
url: 'myurl',
dataType: 'html',
success: function(selectMarkup) {
$('#my_div_id').html(selectMarkup);
}
});
What is dataType property? Here is the description from jquery Docs:
Data Types The $.ajax() function relies on the server to provide information about the retrieved data. If the server reports the return data as XML, the result can be traversed using normal XML methods or jQuery's selectors. If another type is detected, such as HTML in the example above, the data is treated as text.
Different data handling can be achieved by using the dataType option. Besides plain xml, the dataType can be html, json, jsonp, script, or text.
Upvotes: 0
Reputation: 4168
if your code is complete select you can use it :
$('#YourDestinationDiv').html(result);
Upvotes: 1