Javascript按需在生产服务器上不起作用

时间:2012-12-17 16:02:49

标签: 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")
  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)
}

取自此页面:http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

当我在本地运行它时,它可以在所有浏览器中顺利运行。但是在生产服务器上它只适用于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)
        }
    });
});

1 个答案:

答案 0 :(得分:0)

$('#text_content').load(toLoad,'',showNewContent());

需要

$('#text_content').load(toLoad, '', showNewContent);

由于你没有发送数据,你可以这样做

$('#text_content').load(toLoad, showNewContent);
相关问题