[英]IE7 Bug fixed w/ alert - Jquery.ajax
我僅在IE7中有錯誤,當我在代碼中放置警報時-問題已解決。 如此處所述:http://stackoverflow.com/questions/7220603/weird-problem-with-javascript-jquery-which-get-fixed-using-alert,它可能會在異步調用中計時。
事情是我正在使用jQuery.ajax調用並成功調用一個函數-我認為在返回數據后會調用該函數...
$.ajax({
type: "POST",
url: 'myurl.aspx/myMethod',
data: "{ id: 3 }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
DisplayMap(msg.d);
}
});
在我的顯示地圖功能中,我正在Google地圖上設置坐標以概述屬性,如下所示:
function DisplayMap(data) {
var defaultMapZoom = data.Outline.ZoomLevel;
var centerCoordinate = new google.maps.LatLng(data.Outline.Latitude, data.Outline.Longitude);
var myOptions = {
zoom: defaultMapZoom,
center: centerCoordinate,
mapTypeId: google.maps.MapTypeId.HYBRID,
scrollwheel: false
};
map = new google.maps.Map(document.getElementById('googleMap'), myOptions);
var mylistener = google.maps.event.addListener(map, 'tilesloaded', function() {
google.maps.event.removeListener(mylistener);
setTimeout(EnableSearch, 500);
});
setUpProertyBorder(data.Outline.Coordinates);
}
function setUpProertyBorder(coordinates) {
var coordsLatLon = createGoogleMapCoordinateArray(coordinates);
var coordOutline = new google.maps.Polygon({
path: coordsLatLon,
strokeColor: '#ff0000',
strokeOpacity: 1.0,
strokeWeight: 2,
fillOpacity: 0
});
coordOutline.setMap(map);
}
function createGoogleMapCoordinateArray(c) {
var coords = [];
for (var x = 0; x < c.length; x++) {
coords.push(new google.maps.LatLng(c[x].Latitude, c[x].Longitude));
}
return coords;
}
EnableSearch函數只是刪除我在Google地圖上的覆蓋圖。 這在IE 8和9,FF和Chrome中非常有效-但是在IE7中,我沒有通過調用setUpProertyBorder獲得輪廓設置。
我“認為” jQuery.ajax中的“成功”功能僅在返回數據后才調用-因此,我的想法是我的數據在那里-但在IE7中卻沒有。
現在,如果我在setUpProertyBorder中放了一個警報-它在IE7中突然起作用(???)建議? 我看不見什么?
我有一個類似的問題,假設實例化地圖的過程太慢,並且DOM直到現在還沒有准備好進行新的更新(只讀):
coordOutline.setMap(map);
因此,如果您嘗試更新DOM,則會導致失敗。 在使用地圖功能之前通過設置超時來解決問題
setTimeout(function(){setUpProertyBorder(data.Outline.Coordinates);},200);
也許這不是最好的方法,但是它起作用了
即使僅在從Ajax請求中獲取數據時才運行成功語句,它也取決於何時請求實際的Ajax調用。
執行Ajax調用的Javascript是否在運行文檔之前等待文檔加載,即:
<script type="text/javascript">
$(document).ready(function() {
// Your code here...
});
</script>
您還可以使用defer命令確保在頁面加載后就加載了JavaScript:
<script type="text/javascript" defer="defer">
$(document).ready(function() {
// Your code here...
});
</script>
嘗試一下,看看是否可以解決。 讓我知道是否可以,我將進一步調查。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.