【发布时间】:2009-09-30 16:27:28
【问题描述】:
这两天我一直在绞尽脑汁想找到解决办法。我正在使用 jQuery.ajax() 从数据库中获取值以在更改另一个框时更新一个框。 php 脚本从数据库中获取值,然后输出 json。它在 FF 中运行良好,但在所有版本的 IE 中,选择框都没有更新。我已经确认输出的 json 是好的。
这里是 jquery:
function getVendors(dest, selectSup) {
var vend = $('select#sup').val();
$.ajax({
beforeSend: function() {
$("select#dest").parent().addClass('loading');
},
type: "GET",
dataType: "json",
cache: false,
url: '/search/cruiseselect/?type=vendors&supplier=' + vend + '&dest=' + dest,
timeout: 2000,
error: function() {
alert("Failed to submit");
},
success: function(data) {
$("select#sup option").remove();
var any = "<option value=\"any\">-- All Cruise Lines --</option>";
$(any).appendTo("select#sup");
$.each(data, function(i, j) {
if (j != null && j != undefined) {
var sel = j.value == selectSup ? " selected" : "";
var row = "<option value=\"" + j.value + sel + ">" + j.text + "</option>";
//$(row).appendTo("select#sup");
$("select#sup").append(row);
}
});
},
complete: function() {
$("select#dest").parent().removeClass('loading');
}
});
}
jQuery(document).ready(function() {
//dynamic select boxes
$("select#dest").change(function() {
var selectSup = $("select#sup").children("option:selected").val();
getVendors($(this).val(), selectSup);
});
});
我的 php 中有这个
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
echo json_encode($json);
它输出正确的 json,没有额外的逗号或任何东西。更重要的是,如果我使用 alert(j.value + j.text);在我的 .each() 循环中,我在 IE 中获得了正确的数据,所以似乎是 jquery appendTo() 不起作用。
有人有什么想法吗?
【问题讨论】:
标签: javascript php jquery json