0

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


});

2 Answers 2

1

if your code is complete select you can use it :

$('#YourDestinationDiv').html(result);

Sign up to request clarification or add additional context in comments.

Comments

0

$.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.

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.