I am getting an incosistant error in IE8, it happens about half the time. I have cascading drop downs using ajax to fetch the next select box options.
$(function () {
$("#stock_item_id").change(function () {
var stock_item = $("#stock_item_id > option:selected").attr("value");
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/Unit/ForStockItem/" + stock_item,
data: "{}",
dataType: "json",
success: function (data) {
var options = '';
var selected = "0";
for (p in data) {
var unit = data[p];
if (unit.selected == "true") { selected = unit.id; }
options += "<option value='" + unit.id + "'>" + unit.name + "</option>";
}
$("#unit_id").removeAttr('disabled').html(options);
$("#unit_id").val(selected);
}
});
});
});
And the MVC2 controller action
public JsonResult ForStockItem(int id)
{
StockItemRepository stockItemRepository = new StockItemRepository(repository.db);
tblStockItem stockItem = stockItemRepository.Single(id);
return new JsonResult
{
Data = repository.parentList(stockItem.tblUnit.BaseUnitId, stockItem.unit_id)
};
}
It works 100% from firefox, chrome etc and about half the time in IE8. When it doesnt work in IE8 data variable is null in jquery.
If I change the request to a GET and add JsonRequestBehavior = JsonRequestBehavior.AllowGet to the JsonResult it works 100% in IE8 (no other code change). While this is a solution it is not ideal. Is this a known bug with Jquery and IE8, what can I do to fix it and still use POST?
Many Thanks