代码之家  ›  专栏  ›  技术社区  ›  Bill

IE8 jquery weirdness with.click()和.ajax()函数

  •  2
  • Bill  · 技术社区  · 16 年前

    奇怪的问题。。。

    在添加了更多的服务器端调试之后,我发现 handleLookupButton($("#select-circuit").val()); 和 handleLookupButton($(this).text());

    handleLookupButton($(“#选择电路”).val()); 不等待服务器结果。它只是通过ajax循环,就像什么都没发生一样,没有成功,没有错误。

    结束更新

    给出以下jsp片段

    <div id="main-controls" class="main-controls ui-widget ui-corner-all" align="center" style="padding-top: 5px;">
       <form action="#" id="lookupForm">
    
       <div align="right" style="padding-right: 10px; padding-bottom: 5px;">
        <label id="select-circuit-label" class="select-label" style="font-size: 8pt; font-weight: bold">Circuit:
          <input type="text" id="select-circuit" class="main-select" style="font-size: 8pt; height: 13px; width: 100px;">
        </label>
    
        <label id="select-ne-label" class="select-label" style="font-size: 8pt; font-weight: bold">NE:
          <input type="text" id="select-ne" class="main-select" style="font-size: 8pt; height: 13px; width: 100px;" disabled="disabled">
        </label>
    
        <label id="select-customer-label" class="select-label" style="font-size: 8pt; font-weight: bold">Customer:
          <input type="text" id="select-customer" class="main-select" style="font-size: 8pt; height: 13px; width: 100px;" disabled="disabled">
        </label>
       </div>
    
       <div align="center">
         <button id="lookup-button" class="lookup-button ui-widget" >Lookup</button>
       </div>
       </form>
     </div>
    
     <br></br>
    
     <div id="lookup-history-container" class="ui-widget ui-widget-content ui-corner-all" align="center" style="font-size: 8pt; overflow: auto;">
        <b>Lookup History</b>
        <hr class="ui-widget ui-corner-all ui-header" width="80%">
        <br>
        <div align="left">
          <ul id="lookup-history-list">
          </ul>
        </div>
     </div>
    
     <div id="favorites-container" class="ui-widget ui-widget-content ui-corner-all" align="center" style="font-size: 8pt; overflow: auto;">
        <b>Favorites</b>
        <hr class="ui-widget ui-corner-all ui-header" width="80%">
        <br>
        <div align="left">
          <ul id="favorite-list" style="padding:2px; margin:2px; border-bottom: thin;">
              <c:if test="${fn:length(favorites)> 0}">
                 <c:forEach var="favorite" items="${favorites}">
                     <c:set var="companyTrimed" value="${favorite.company}"/>
                     <li>
                      <b><span class="past-lookup-circuit"><c:out value="${favorite.circuit}" /></span></b>
                      <span class="delete-favorite-icon ui-icon ui-icon-trash" 
                               style="width: 14px; float: right;"
                               title="DELETE this Favorite" 
                               circuit='<c:out value="${favorite.circuit}" />' 
                               >
                        </span><br>
                        <span class="lightly-darkened" style="padding-left: 20px;"><c:out value="${fn:substring(companyTrimed,0,20)}" />...</span>
    
                     </li>
                 </c:forEach>
              </c:if>
          </ul>
        </div>
     </div>
    

    我有以下jQuery代码

    // This is to look up a circuit
    $("#lookup-button").live("click", function() {
        handleLookupButton($("#select-circuit").val());
    });
    
    // Handle loading from history
    $(".past-lookup-circuit").live("click", function() {
        $("#select-circuit").removeAttr("disabled");
        $("#select-ne").val("");
        $("#select-ne").attr("disabled", "disabled");
        $("#select-circuit").val($(this).text());
        $("#select-circuit").fadeOut("slow");
        $("#select-circuit").fadeIn("slow");
        handleLookupButton($(this).text());
    });
    

    阿尔索

    function handleLookupButton(circuit) {
    
    var ne = "";
    var data = "circuit=" + circuit + "&ne=" + ne  + "&random=" + Math.random();
    
    $("#test-results-container").html(
            "<b>Checking EON...</b><br><img src='images/small-loader.gif'>");
    $("#test-results-container").show();
    
    $(".tl1-results").hide();
    
    alert("IE8 test: \n\n>" + data + "<");
    
    $.ajax( {
        type : "POST",
        url : "test.html",
        data : data,
        success : function(xhr) {
    
             alert("IE8 test: \n\n" + xhr);
    
                     //.... stuff snipped here ....     
    
    
        },
        error : function(xhr) {
            $("#test-results-container").html("<span id='ajax-error-lookup'><b>Error: <b>" + xhr.statusText + "</span>");
            $("#test-detail-container").html(xhr.responseText);
        }
    });
    

    }

    这就是问题所在。

    $("#lookup-button").live 函数 handleLookupButton(circuit)

    $(".past-lookup-circuit").live 功能。这个 手动Lookupbutton(电路)

    对于这两个执行,var数据字符串看起来是相同的。即使我把电路号硬编码到 手动Lookupbutton(电路) $(“#查找按钮”).live 不起作用,但是

    我肯定我错过了一些简单的东西,但我被难住了。顺便说一句,这在所有其他浏览器和ie7兼容模式下都可以正常工作。

    3 回复  |  直到 16 年前
        1
  •  1
  •   Ethode    15 年前

    而不是使用 <button> 尝试使用

    <input type="button" id="lookup-button" class="lookup-button ui-widget" value="Loopup" />
    
        2
  •  1
  •   snowlark    15 年前

    你知道,如果你还想使用$('button#lookup button'),你可以用另一种方法来攻击它。。。

    电话 我的ajax函数,传递我需要的参数。这样,我就有机会对其他类似GUI的事件请求重用相同的ajax功能。。。

    我还提供了一个存储“success”处理函数的变量。这样,我的ajax调用的成功结果就会调用另一个函数来处理结果。。。div中的success或error condition面板( <span class="success">congratulations!</span>

    可能看起来“更复杂”,但它提供了更大的灵活性,对我来说。。。

    您的里程数可能会有所不同。:)

        3
  •  0
  •   Bill    16 年前

    问题是点击一个“按钮”标签。

    <button id="lookup-button" class="lookup-button ui-widget" >Lookup</button>
    

    做 不 作为启动.ajax函数的锚。

    <span id="lookup-span">Lookup</span>
    

    呜呜,我下一个IE8 “功能”。

    推荐文章