Javascript随需应变在生产服务器上不起作用
我在生产服务器上的脚本出现了一个奇怪的问题 我正在使用此解决方案按需运行脚本:Javascript随需应变在生产服务器上不起作用,javascript,jquery,Javascript,Jquery,我在生产服务器上的脚本出现了一个奇怪的问题 我正在使用此解决方案按需运行脚本: function loadjscssfile(filename, filetype){ if (filetype=="js"){ //if filename is a external JavaScript file var fileref=document.createElement('script') fileref.setAttribute("type","text/javascript") fi
function loadjscssfile(filename, filetype){
if (filetype=="js"){ //if filename is a external JavaScript file
var fileref=document.createElement('script')
fileref.setAttribute("type","text/javascript")
fileref.setAttribute("src", filename)
}
else if (filetype=="css"){ //if filename is an external CSS file
var fileref=document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref)
}
摘自本页:
当我在本地运行它时,它在所有可能的浏览器中都能顺利运行。但在生产服务器上,它只能在IE 8及更旧版本中工作
下面是我使用此函数调用的实际代码:
$(document).ready(function () {
$("#vertical_cssmenu a").hover(function() {
$(this).stop().animate({ backgroundColor: "#f22d00"}, 350);
},function() {
$(this).stop().animate({ backgroundColor: "#e5e5e5" }, 350);
});
$("#vertical_cssmenu a").click(function() {
var toLoad = $(this).attr('href')+' #text_content > *';
$('#text_content').fadeOut(500,loadContent);
$(this).attr('href').substr(0,$(this).attr('href').length-4);
function loadContent() {
$('#text_content').load(toLoad,'',showNewContent());
}
function showNewContent() {
$('#text_content').fadeIn(1000);
}
return false;
});
});
请帮帮我,伙计们:
编辑:以下是页面上主要javascript的代码:
// dynamiczne ladowanie CSS i JS
function ensureUploadScriptIsLoaded() {
if (self.uploadScript) { // Already exists
return;
}
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.id = 'uploadScript';
script.type = 'text/javascript';
script.src = "js/vertical.js";
head.appendChild(script);
}
// fullscreen BG
$(window).load(function ()
{
var theWindow = $(window),
$bg = $("#bg"),
aspectRatio = $bg.width() / $bg.height();
function resizeBg()
{
if ((theWindow.width() / theWindow.height()) < aspectRatio)
{
$bg.removeClass()
.addClass('bgheight');
}
else
{
$bg.removeClass()
.addClass('bgwidth');
}
}
theWindow.resize(function ()
{
resizeBg();
}).trigger("resize");
});
// RSS
$(document).ready(function ()
{
$('#divRss').FeedEk(
{
FeedUrl: 'http://someurl.here',
MaxCount: 5,
ShowDesc: true,
ShowPubDate: true
})
// baner
$('#acc-holder').easyAccordion(
{
autoStart: true,
slideInterval: 5000,
slideNum: false
});
// menu animacja
$("#horizontal_cssmenu a").hover(function ()
{
$(this).stop().animate(
{
backgroundColor: "#f22d00"
}, 750);
}, function ()
{
$(this).stop().animate(
{
backgroundColor: "#790079"
}, 350);
});
// ladowanie
$("#horizontal_cssmenu a").click(function ()
{
var toLoad = $(this).attr('href');
$('#contentsth').fadeOut('150', loadContent);
window.location.hash = $(this).attr('href').substr(0, $(this).attr('href').length - 4);
function loadContent()
{
$('#contentsth').load(toLoad, showNewContent);
}
function showNewContent()
{
$('#contentsth').fadeIn(1000, ensureUploadScriptIsLoaded);
}
return false;
});
var hash = window.location.hash.substr(1);
var href = $('#horizontal_cssmenu a').each(function ()
{
var href = $(this).attr('href');
if (hash == href.substr(0, href.length - 4))
{
var toLoad = hash + '.htm';
$('#contentsth').load(toLoad)
}
});
});
需要
$('#text_content').load(toLoad, '', showNewContent);
既然你没有发送数据,你可以这样做
$('#text_content').load(toLoad, showNewContent);
也许您正在使用web浏览器的同源策略?它仅在IE 8及更旧版本中有效。。。你是说它在IE7中不起作用?或者它在chrome firefox safari和opera中不起作用errors@Philipp这对脚本和css包含不重要。您调用showNewContent太快,请删除应用的更改。。。问题仍然存在:/好的,伙计们,谢谢你们的帮助,我设法调试了它。。。事实证明,前面提到的脚本也包含在加载文档的头部分,显然这些脚本阻止了正确的脚本执行:经过一些认真的测试后,再次出现问题。。。出于某种原因,它在safari上不起作用。有谁能建议一种更好的、更跨浏览器的方式来按需处理脚本吗?啊,另外一个老IE现在也不工作了,看起来他们实际上是通过ajax LOL从加载的文档加载脚本的?
$('#text_content').load(toLoad, showNewContent);