Chrome、Firefox、IE8では正常に動作します。しかし、IE7でエラーが発生します。ここに私のjquery onchangeイベントがあります。IE7でJSONが定義されていません
$('select#NationId').change(function() {
var nationId = $(this).val();
$.ajax({
url: 'LoadAreas',
type: 'POST',
data: JSON.stringify({ nationId: nationId }),
dataType: 'json',
contentType: 'application/json',
success: function (data) {
$('select#AreaId').get(0).options.length = 0;
$('select#AreaId').append('<option value="0">Select All</option>');
$.each(data, function (val, Areas) {
$('select#AreaId').append('<option value="' + Areas.Id + '">' + Areas.Name + '</option>');
});
}
});
});
コントローラ
[HttpPost]
public ActionResult LoadAreas(int nationId)
{
var _Areas = (from c in SessionHandler.CurrentContext.ChannelGroups
join cgt in SessionHandler.CurrentContext.ChannelGroupTypes on c.ChannelGroupTypeId equals cgt.ChannelGroupTypeId
where cgt.Name == "Area" && c.ParentChannelGroupId == nationId
select new AreaName() { Id = c.ChannelGroupId, Name = c.Name }).OrderBy(m => m.Name);
if (_Areas == null)
return Json(null);
List<AreaName> managers = (List<AreaName>)_Areas.ToList();
return Json(managers);
}
私は。 onchangeイベントは起動しません。 – bladerunner
まず、JSON2へ実際にホットリンクしていないと仮定しています;-)第2に、*イベント*はまったく起動していませんか? (これはIE7だけですか?) –
json2.jsファイルにあるスクリプトをコピーして、それを自分のプロジェクトに追加し、そのマスターページのファイルを参照しました。 @bladerunner - あなたの '.change'ハンドラで' alert(nationId); 'を実行した場合、何もありません。 – bladerunner