王東校的Blog

          2012年6月26日 #

          JQUERY 的AJAX只執行一次問題

          $.ajax({
                      url: 'Ajax/OrderBy.aspx',
                      data: {AppIds: sortedAppids},
                      dataType: 'xml',
                      type: 'POST',
                      success: function(xml)
                      {
                         alert("排序成功!");
                      }
                  });
           
          ajax在同步交互時,第一次提交正常,再第二次提交如果和上次提交的url地址相同時將不進行提交,會用上次的返回值。這樣處理也許是ext別有良苦用心,但是,如果遇到每次必須提交時,例如一次提交后臺的數據已經被修改了,再次提交返回的結果其實是不一樣的,這樣就需要特殊處理了。
          方法一:GET方式加參數
          原代碼:
           
          view plaincopy to clipboardprint?
              var conn = Ext.lib.Ajax.getConnectionObject().conn;   
                      conn.open("get", HOST+'/OrgUserAction_checkPassword.action?id='+id+'&passwordOld='+checkValue,false);   
                      conn.send(null);   
              //      alert(conn.responseText);  
           
           
          處理后
           
          view plaincopy to clipboardprint?
              var conn = Ext.lib.Ajax.getConnectionObject().conn;   
                      conn.open("get", HOST+'/OrgUserAction_checkPassword.action?id='+id+'&passwordOld='+checkValue+'&temp='+new Date(),false);   
                      conn.send(null);   
              //      alert(conn.responseText);  
           
           
          添加了一個臨時參數temp=new Date();
          這樣保證了每次提交的url是不同的,從而達到了每次都會提交的效果。
          方法二:
          把get 改成post就可以了type: 'POST',

          posted @ 2012-06-26 14:56 王東校 閱讀(685) | 評論 (1)編輯 收藏

          IE6下鏈接ONCLICK事件處理中的請求被ABORTED

          一大早發現,ie6下點發起對話沒法彈出窗口,ff瀏覽器就是可以的。開啟HttpWatch檢測,發現點擊的被aborted。
          查找資料顯示aborted的原因如下。
          The (Aborted) value is more complex in its origin. It occurs when IE has started to process the request for a URL (e.g. to download an image), but then decides to cancel the operation. Here are some examples of when this can occur:
          If you click on a link or bookmark while a page is downloading, or click on IE’s Stop button, you will see that IE cancels any requests which are still active and HttpWatch shows the (Aborted) result.
          A CSS rollover image on a page will start a request when the mouse pointer is moved into its active area. If the mouse pointer quickly moves away again, IE may abort the request if it has not already completed.
          Sometimes javascript is used to fire off requests for background tasks or to gather statistics on a page. Often this can lead to aborted results if the javascript does not wait for the response to be received from the server.
          繼續尋找根源,搜索到發現這個問題是ie6中一個底層 機制的bug,之后的版本已經解決了。據說<a href="javascript:void(0)">或者<a href=#">這樣使用a標簽的話并不能阻止a標簽最后觸發一個什么行為,導致ie6會錯誤的認為頁面刷新或者重定向了,并且中斷了當前所有連 接,這樣新的加載就被aborted了。解決方案最簡單的方法有兩個,一個是這樣使用a標簽<a href="xxx(); return false;">,另外一個就是用div替換a標簽來用。至此,問題總算解決。
          在開發中常使用<a>標簽代替button,好處在于可以利用a:hover樣式做mouseover效果,但下面的代碼在IE6下就有問題,onclick中的請求被aborted。
          <a href="javascript:void(0);" onclick="$('current').src='images/001.jpg';">切換圖片</a>,IE6下圖片不顯示。
          <a href="javascript:void(0);" onclick="MyJrjRelation.checkAttention();">關注此人</a>,IE6下請求失敗。
          解決方法:
          1. 不使用onclick,但必須保證處理函數不返回值,否則瀏覽器將清空頁面,只顯示函數的結果。如果checkAttention返回false,瀏覽器中就會顯示false。
          <a href="javascript:MyJrjRelation.checkAttention();">關注此人</a>
          <a href="javascript:void(MyJrjRelation.checkAttention());">關注此人</a>   void返回undefined;
          2. 在onclick上加return false阻止瀏覽器執行href。href屬性還是必須的,否則鏈接就樣式失效了。
          <a href="javascript:void(0);" onclick="MyJrjRelation.checkAttention();return false;">關注此人</a>
          總結來說<a href="javascript:void(0);" onclick="MyJrjRelation.checkAttention();return false;">的兼容性最好。
          原文地址:
          http://blog.csdn.net/wangjj_016/article/details/5304784

          posted @ 2012-06-26 14:54 王東校 閱讀(255) | 評論 (0)編輯 收藏

          主站蜘蛛池模板: 凯里市| 兰州市| 新源县| 巴林右旗| 积石山| 百色市| 阿克| 堆龙德庆县| 顺平县| 嘉禾县| 新平| 襄垣县| 沙河市| 长岛县| 临泉县| 大埔县| 金溪县| 喀喇沁旗| 余姚市| 黔西| 米易县| 乐业县| 阿拉善左旗| 交口县| 留坝县| 东明县| 青龙| 铜鼓县| 龙胜| 舞阳县| 大连市| 饶平县| 黄龙县| 普兰店市| 广东省| 望都县| 青浦区| 随州市| 青岛市| 龙州县| 宜君县|