I am currently trying to return a database call to fill a dropdown box. When I go to cycle through the list returned, however, I am getting a "callback is undefined" error. I've tried this code two ways, and neither is working.
I've tried:
$('#Vehicle_KovId_value').change(function () {
var kovID = $(this).val();
var drop2 = $('#Vehicle_BodyStyle_value');
if (kovID != null && kovID != '') {
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option('Please Select One', '-1');
$.ajax({
type: "GET",
url: '/Ajax/Index',
async: false,
data: { KovID: kovID },
contentType: "application/object; charset=utf-8",
success: function (record) {
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option("Please Select One", "-1");
$.each(function (index, item) {
drop2.get(0).options[drop2.get(0).options.length] = new Option(item.Display, item.Value);
});
},
error: function () {
$('#Vehicle_BodyStyle_value').get(0).options.length = 0;
$('#Vehicle_BodyStyle_value').get(0).options[0] = new Option("Error!", "-1");
alert("Failed to load styles");
}
});
}
});
I've also tried:
$('#Vehicle_KovId_value').change(function () {
var kovID = $(this).val();
var drop2 = $('#Vehicle_BodyStyle_value');
if (kovID != null && kovID != '') {
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option('Please Select One', '-1');
$.ajax({
type: "GET",
url: '/Ajax/Index',
async: false,
data: { KovID: kovID },
contentType: "application/object; charset=utf-8",
success: function (record) {
drop2.get(0).options.length = 0;
drop2.get(0).options[0] = new Option("Please Select One", "-1");
fillBStyles(record);
// $.each(function (index, item) {
// drop2.get(0).options[drop2.get(0).options.length] = new Option(item.Display, item.Value);
// });
},
error: function () {
$('#Vehicle_BodyStyle_value').get(0).options.length = 0;
$('#Vehicle_BodyStyle_value').get(0).options[0] = new Option("Error!", "-1");
alert("Failed to load styles");
}
});
}
});
function fillBStyles(r) {
var drop2 = $('#Vehicle_BodyStyle_value');
$.each(function (index, item) {
drop2.get(0).options[drop2.get(0).options.length] = new Option(item.Display, item.Value);
});
}
Both of which give me the error:
TypeError: callback is undefined
The data object being returned, record
, is a list of database objects that I have to pull two pieces from.
How can I fix this "callback" error so that I can use my data in my function?
jquery-1.7.js(line 654)
which readsif ( callback.call( object[ name ], name, object[ name ] ) === false ) {
then breaks if thatif
is true.$.each(function (index, item) {
from what Firebug is showing me.