jQuery .load() not working in IE10

爱⌒轻易说出口 提交于 2019-12-31 05:25:30

问题


I am having trouble with IE 10 and jQuery .load(). I have a PHP page that I load once the website proper has loaded:

$(document).ready( function() { 
    $('#words').html('<div id="loading"><div id="loading-text">Analyzing frequency data...</div><div id="loading-image"><img src="loading.gif"></div></div>');
    $('#words').load('translate.php?character=<?php echo $character1;?>');
}); 

It works fine in Chrome, but in IE the "loading" text appears for about 1 second and disappears, and the translate.php file never loads.

If I change the code to

$(document).ready( function() { 
    $('#words').html('<div id="loading"><div id="loading-text">Analyzing frequency data...</div><div id="loading-image"><img src="loading.gif"></div></div>');
    $('#words').load('index.php');
}); 

it loads fine. However, if I change the code to:

$(document).ready( function() { 
    $('#words').html('<div id="loading"><div id="loading-text">Analyzing frequency data...</div><div id="loading-image"><img src="loading.gif"></div></div>');
    $('#words').load('translate.php?character=章');
}); 

is still doesn't work.

Also, when I echo the character in the translate.php file it shows up with "?" which leads me to believe there's a character encoding problem. However:

  • All pages are encoded "UTF-8 without BOM"
  • I have <meta charset="UTF-8"> in the <head> tags
  • Chinese characters that aren't loaded from translate.php show up fine

Could it be that the jQuery load is stuffing the encoding up in IE only?

I am lost!

Thanks, Dan


回答1:


Try url encoding the character in the url

$(document).ready( function() { 
    $('#words').html('<div id="loading"><div id="loading-text">Analyzing frequency data...</div><div id="loading-image"><img src="loading.gif"></div></div>');
    $('#words').load('translate.php?character='+encodeURIComponent('<?php echo $character1;?>'));
});


来源:https://stackoverflow.com/questions/16248060/jquery-load-not-working-in-ie10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!