在開發(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)部默認(rèn)為是 window這個大對象,如下面的this如是放在一個ajax的里面指的是當(dāng)前域名ajax對象
解決方法:
復(fù)制代碼 代碼如下:
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
}
});
}
復(fù)制代碼 代碼如下:
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
}
});
}
新聞熱點
疑難解答
圖片精選