jQuery不适用于Internet Explorer 9(但适用于Firefox、Chrome和Opera)
我写了一个jQuery脚本,可以在Chrome、Firefox和Opera中使用,但不能在internetexplorer9中使用 基本上,使用ajax在后台加载的图像应该是fadein,并在其他图像上载到同一文件夹时动态替换。在Internet Explorer中,脚本无法工作,图像也无法加载 我试着用firebug和IE开发者工具栏进行调试,但我有点经验不足 你能帮我吗?谢谢大家! jQuery代码jQuery不适用于Internet Explorer 9(但适用于Firefox、Chrome和Opera),jquery,cross-browser,internet-explorer-9,Jquery,Cross Browser,Internet Explorer 9,我写了一个jQuery脚本,可以在Chrome、Firefox和Opera中使用,但不能在internetexplorer9中使用 基本上,使用ajax在后台加载的图像应该是fadein,并在其他图像上载到同一文件夹时动态替换。在Internet Explorer中,脚本无法工作,图像也无法加载 我试着用firebug和IE开发者工具栏进行调试,但我有点经验不足 你能帮我吗?谢谢大家! jQuery代码 $(window).load(function () { var data;
$(window).load(function () {
var data;
$('.nascosto').hide();
$('.ciccio').hide();
$.ajax({
type: "GET",
url: "phpdelete.php",
success: function (data) {
$("<img/>").attr("src", data).load(function () {
$(this).remove();
});
}
});
setInterval(prova, 1000);
function prova() {
$.ajax({
type: "GET",
url: "phpdelete.php",
success: function (data2) {
if (data2 != data) {
$('.ciccio').fadeOut(2000, function () {
$("<img/>").attr("src", data2).load(function () {
$(this).remove();
$('.ciccio').css('background-image', 'url(' + data2 + ')').delay(500).fadeIn(2000);
data = data2;
});
});
}
}
});
}
});
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
$(窗口)。加载(函数(){
var数据;
$('.nascosto').hide();
$('.ciccio').hide();
$.ajax({
键入:“获取”,
url:“phpdelete.php”,
成功:功能(数据){
$(“”).attr(“src”,data2).load(函数(){
$(this.remove();
$('.ciccio').css('background-image','url('+data2+')).delay(500).fadeIn(2000);
数据=数据2;
});
});
}
}
});
}
});
我解决了这个问题。调试本身无法帮助我,因为代码实际上是干净的:即使使用InternetExplorer9开发者工具控制台,我也没有发现任何错误
因为没有错误,但仍然没有加载图像,所以问题必须在ajax调用中解决。我添加此代码是为了在出现错误时发出警报:
jQuery代码
$(window).load(function () {
var data;
$('.nascosto').hide();
$('.ciccio').hide();
$.ajax({
type: "GET",
url: "phpdelete.php",
success: function (data) {
$("<img/>").attr("src", data).load(function () {
$(this).remove();
});
}
});
setInterval(prova, 1000);
function prova() {
$.ajax({
type: "GET",
url: "phpdelete.php",
success: function (data2) {
if (data2 != data) {
$('.ciccio').fadeOut(2000, function () {
$("<img/>").attr("src", data2).load(function () {
$(this).remove();
$('.ciccio').css('background-image', 'url(' + data2 + ')').delay(500).fadeIn(2000);
data = data2;
});
});
}
}
});
}
});
error: function (jqXHR, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
Chrome没有显示错误,而Internet Explorer发出NotTransport错误警报。
经过一些搜索,我发现了一条建议在ajax调用之前添加此内容的线索:
$.support.cors = true;
它是有效的。请提供一个提琴。您需要以某种方式进行调试,并找出首先出现问题的原因。下次您应该真正缩进代码。当涉及到调试时,它肯定会有所帮助。(我刚刚用jsFiddle TidyUp清理了它。)我知道我需要调试,问题是我不知道它是如何完成的:)我尝试创建一个jsFiddle(),但在我的脚本中有一个外部php页面的ajax请求,它在jsFiddle上不起作用。。。实际上可以向另一台服务器发出ajax请求吗?对不起,我还在学诀窍呢!。load(函数)从1.8版开始就过时了,您需要停止使用它(并在发布jquery发行说明时阅读它们以防止此类oops问题)。load用于通过ajax加载数据: