开发者

How to populate DropDown on page load?

开发者 https://www.devze.com 2022-12-11 23:25 出处:网络
I want to populate a DropDown contro开发者_JAVA技巧l on page load using AJAX. I have the code and it is working, but I am not following as to which event to use.I\'m assuming you\'re not using a JavaS

I want to populate a DropDown contro开发者_JAVA技巧l on page load using AJAX. I have the code and it is working, but I am not following as to which event to use.


I'm assuming you're not using a JavaScript framework, but this is simple with jQuery.

$(document).ready(function(){ 
    $("#some_div").load("/dropdown.html", function(){
        [any additional code to make it work]
    });
});

I hope I'm understanding your question correctly.


Firstly, what does the ajax callback return? Partial html formatted as json/xml, or straight up HTML?

One way would be to just re-build the select element and iterate and append option elements, then use the replaceWith method to replace the dropdown. If you have an event on the dropdown, you may need to use liveQuery in order for it to "stick". It would help seeing the code you currently have in order for a definitive answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消