欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS this作用域以及GET傳輸值過長的問題解決方法

 更新時間:2013年08月06日 16:20:45   作者:  
專IE7瀏覽器,IE URL參數(shù)過長問題,引發(fā)HTTP Status 122報錯;this作用域問題,對應的解決方法如下,感興趣的朋友可以參考下,希望對大家有所幫助
在開發(fā)項目的時候,前端遇到兩個比較隱蔽的問題。

問題一.專IE7瀏覽器,IE URL參數(shù)過長問題,引發(fā)HTTP Status 122報錯
原因:在IE6.8下沒有什么問題,但在IE7就不兼容get參數(shù)過長,google上說“Don't use the GET method in Ajax Apps, if you can void it, because IE7 craps out with more than 2032 characters in a get string”

解決方法:
把原項目采用jsonp get的數(shù)據(jù)方法改為 常規(guī)post數(shù)據(jù)方法

問題二. this作用域問題
原因:this如果不是在對象內(nèi)部默認為是 window這個大對象,如下面的this如是放在一個ajax的里面指的是當前域名ajax對象

解決方法:
復制代碼 代碼如下:

var test={};
test.getflash = 2;
test.test =function(){
alert(this.getflash); //2
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert(this.getflash); //等于undefine
}
});
}

解決方法:
復制代碼 代碼如下:

test.test =function(){
var thisValue = this;
alert(thisValue.getflash); //2
$.ajax({
type: "POST",
url: "some.php",
data: "name=John&location=Boston",
success: function(msg){
alert(thisValue.getflash); //2
}
});
}

相關文章

最新評論