$.ajax({
url: 'Ajax/OrderBy.aspx',
data: {AppIds: sortedAppids},
dataType: 'xml',
type: 'POST',
success: function(xml)
{
alert("排序成功!");
}
});
ajax在同步交互時,第一次提交正常,再第二次提交如果和上次提交的url地址相同時將不進行提交,會用上次的返回值。這樣處理也許是ext別有良苦用心,但是,如果遇到每次必須提交時,例如一次提交后臺的數(shù)據(jù)已經(jīng)被修改了,再次提交返回的結(jié)果其實是不一樣的,這樣就需要特殊處理了。
方法一:GET方式加參數(shù)
原代碼:
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);
添加了一個臨時參數(shù)temp=new Date();
這樣保證了每次提交的url是不同的,從而達到了每次都會提交的效果。
方法二:
把get 改成post就可以了type: 'POST',
一大早發(fā)現(xiàn),ie6下點發(fā)起對話沒法彈出窗口,ff瀏覽器就是可以的。開啟HttpWatch檢測,發(fā)現(xiàn)點擊的被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.
繼續(xù)尋找根源,搜索到發(fā)現(xiàn)這個問題是ie6中一個底層 機制的bug,之后的版本已經(jīng)解決了。據(jù)說<a href="javascript:void(0)">或者<a href=#">這樣使用a標(biāo)簽的話并不能阻止a標(biāo)簽最后觸發(fā)一個什么行為,導(dǎo)致ie6會錯誤的認(rèn)為頁面刷新或者重定向了,并且中斷了當(dāng)前所有連 接,這樣新的加載就被aborted了。解決方案最簡單的方法有兩個,一個是這樣使用a標(biāo)簽<a href="xxx(); return false;">,另外一個就是用div替換a標(biāo)簽來用。至此,問題總算解決。
在開發(fā)中常使用<a>標(biāo)簽代替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();">關(guān)注此人</a>,IE6下請求失敗。
解決方法:
1. 不使用onclick,但必須保證處理函數(shù)不返回值,否則瀏覽器將清空頁面,只顯示函數(shù)的結(jié)果。如果checkAttention返回false,瀏覽器中就會顯示false。
<a href="javascript:MyJrjRelation.checkAttention();">關(guān)注此人</a>
<a href="javascript:void(MyJrjRelation.checkAttention());">關(guān)注此人</a> void返回undefined;
2. 在onclick上加return false阻止瀏覽器執(zhí)行href。href屬性還是必須的,否則鏈接就樣式失效了。
<a href="javascript:void(0);" onclick="MyJrjRelation.checkAttention();return false;">關(guān)注此人</a>
總結(jié)來說<a href="javascript:void(0);" onclick="MyJrjRelation.checkAttention();return false;">的兼容性最好。
原文地址:
http://blog.csdn.net/wangjj_016/article/details/5304784