function get_login_form() { var request = new XMLHttpRequest(); request.open('GET', '/login/', true); request.onload = function() { if (request.status >= 200 && request.status < 400) { var data = for(var i in data) { var u = data[i]['fields']['part_number'] + ' - ' + data[i]['fields']['part_name'] choices.push({ value: String(data[i].pk), label: u, }); } populateParts(choices); } else { console.log("server error"); } }; request.onerror = function() { console.log("error on request"); }; request.send(); }