1

I tried caching my data in the MVC side that is returned to the client via Json. Not sure why its running so slow to create these dropdownlist?

I do have 3 or 4 simlar controls on a page.

My code, how can I speed up the load?:

function GetAuditStatusTypeSelected(container, selected) {
    var url = '/AMS/Audit/GetAuditStatusTypes';
    $.ajax({
        url: url,
        type: 'post',
        success: function (result) {
            $.each(result, function (i, item) {
                container.append($('<option/>').text(result[i].Audit_Status_Type).attr('value', result[i].Audit_Status_ID));
            });

            if (selected > 0) {
                container.find('option[value="' + selected + '"]').attr("selected", true);
            } else {
                container.append($('<option selected />').text('').attr('value', '0'));
            }

        },
        error: function (xhr, err) {
            alert(url + ' : ' + formatErrorMessage(xhr, err));
        }
    });
}
tereško
  • 58,060
  • 25
  • 98
  • 150
Chaka
  • 1,709
  • 11
  • 33
  • 58
  • 1
    What is slowing down? The Response time or Page rendering time? You should check the Chrome/Firebug network tab to see the time and timeline. Then you can identify what is wrong! – Fals Dec 02 '13 at 18:06
  • Page loads fine, but controls take awhile to load. They seem empty when the page loads and take a few seconds to populate. – Chaka Dec 02 '13 at 18:09
  • live example or jsfiddle / codepen would help – qdev Dec 02 '13 at 18:22
  • If you have too many items to insert into each select (3-4 as you say), appending each option to the DOM could be the cause. I'd try to build & append the whole list at once. Try this (you could retrieve all 4 lists at once): http://stackoverflow.com/questions/5952284/jquery-fill-dropdown-with-json-data – qdev Dec 02 '13 at 18:30

0 Answers0