我有一个jQuery中的代码片段(AJAX)。
但在我的情况下,除了IE浏览器之外,它在所有浏览器中都可以正常工作。我没有在IE 6/7中进行测试。它会弹出这个错误...
我查看了jquery.js文件,发现它在这个函数中出错...
实际上
当用户在谷歌地图的上下文菜单中点击某个项目时,则执行“doSomethingWithData1”和“doSomethingWithData2”。以下是一些上下文菜单的代码。
$.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&value=5', doSomething);
这是一个函数(在Google地图上显示图标并更改一些输入字段的值)。
function doSomething(data) {
data = data.trim();
data = data.split(",");
var stopName = data[0];
var stopLat = data[1];
var stopLon = data[2];
$("#start").val(stopName);
if (startMarker == null) {
startMarker = new google.maps.Marker({
position: new google.maps.LatLng(stopLat,stopLon),
map: map,
zIndex: 2,
title: stopName,
icon: startImage
});
} else {
startMarker.setPosition(new google.maps.LatLng(stopLat,stopLon));
}
}
但在我的情况下,除了IE浏览器之外,它在所有浏览器中都可以正常工作。我没有在IE 6/7中进行测试。它会弹出这个错误...
![jquery error in IE 8](https://istack.dev59.com/QRoyf.webp)
// resolve with given context and args
resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
firing = 1;
try {
while( callbacks[ 0 ] ) {
callbacks.shift().apply( context, args );
}
}
finally {
fired = [ context, args ];
firing = 0;
}
}
return this;
},
实际上
callbacks.shift().apply( context, args );
有人能帮忙吗?问题出在哪里?同样的问题也出现在 jquery-1.4.4.js 上。
编辑:这是我的完整代码...
// Set some events on the context menu links
contextMenu.find('a').click( function()
{
// fade out the menu
contextMenu.fadeOut(75);
// The link's href minus the #
var action = $(this).attr('href').substr(1);
switch (action) {
case 'startMenu':
$.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&radijus=5', doSomethingWithData1);
break;
case 'stopMenu':
$.get('someScript.php?lat=' + clickedLatLng.lat() + '&lon=' + clickedLatLng.lng() + '&radijus=5', doSomethingWithData2);
break;
}
return false;
});
当用户在谷歌地图的上下文菜单中点击某个项目时,则执行“doSomethingWithData1”和“doSomethingWithData2”。以下是一些上下文菜单的代码。
// Hover events for effect
contextMenu.find('a').hover( function() {
$(this).parent().addClass('hover');
}, function() {
$(this).parent().removeClass('hover');
});
这是关于AJAX的内容
$.ajaxSetup ({
cache: false
});
这是我如何包含我的 jQuery 脚本。
<!-- Google Maps -->
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<!-- Load Javascript / jQuery -->
<script type="text/javascript" src="js/jquery-1.5.js"></script>
<script type="text/javascript" src="js/jquery.ui.core.js"></script>
<script type="text/javascript" src="js/jquery.ui.position.js"></script>
<script type="text/javascript" src="js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="js/jquery.ui.autocomplete.js"></script>
<link rel="stylesheet" href="js/jquery.ptTimeSelect.css" type="text/css" media="all" />
<script type="text/javascript" src="js/jqtransformplugin/jquery.jqtransform.js"></script>
<link rel="stylesheet" href="js/jqtransformplugin/jqtransform.css" type="text/css" media="all" />
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
jquery.js
文件中遇到了错误,99.9999% 的情况下,这是 你的 代码出了问题。我会进一步调查。 - Dutchie432setPosition
回调函数的第一行设置一个断点,并逐步执行它。查看生成的data
并确保它是有意义的。找出实际失败的代码行(你引用的jQuery行只是调用你的回调函数;更有可能错误在回调函数内部)。 - T.J. Crowder