0

I am having a problem with IE. In my app, I have a dialog that the user can display. The dialog is built with data from an AJAX call. I then register a one time event handler for the button. In FF, Chrome, and Safari, I have no problems. The dialog displays and the button works. This has worked for a long time.

In IE, the dialog display, but sometimes the event handler does not fire. Clicking the button has no effect. This doesn't always happen. So far, it seems happen the first time you view the page after opening IE. Closing the dialog and reopening sometimes fixes it. Reloading the page sometimes fixes it. Once it is fixed, it doesn't seem to fail again regardless of page reload. Quitting IE is required to get the problem to re-occur. I haven't been able to use the developer tools because the problem disappears when the developer tools are open.

$('#btn_school_choices').button('loading');

$.ajax({
  type: 'GET',
  url: 'ajax/optimized_colleges.php',
  dataType: 'json',
  success: function(data, status, xhr) { 
    // Some code to prepare the data returned

    // Build the dialog using the data and add to DOM
    $('#modal_opt_in').html(ich.dialog_optimize_college_selection(optinData));

    $('#btn_school_choices').button('reset');

    // Add Event Handler to Button in Dialog
    $('#btn_add_colleges').one('click', function() { ... }

    // Show the Dialog
    $('#modal_opt_in').modal({backdrop: 'static', show: true});

  error: function(xhr) { ... }
});

I have tried using on() and off() and the same issue occurs. At this point, I have been trying to fix this for about two weeks. Any help would be appreciated.

The button should exist at the time of registering the event handler as it is added to the DOM two lines prior. (Even when the event handler fails, the dialog displays with the button, So the two lines prior to registering the event handler and the line after the event handler work.

4

2 回答 2

1

问题是我在事件处理程序中留下了一个 console.log 调用。删除 console.log 调用解决了这个问题。太糟糕了,IE 没有给你任何它不能处理呼叫的迹象。它只是静静地死去。调试很痛苦,因为它在您打开开发者工具后就可以工作。

于 2013-04-29T04:00:23.757 回答
0

也许在文档上绑定事件以确保它不是由不存在的元素绑定问题引起的。

$(document).one('click', '#btn_add_collegues', function () {
    // ...
});
于 2013-04-28T07:56:42.853 回答