简体   繁体   English

如何使用本地文件夹中的图像而不是jquery中的url使用图像?

[英]How to use image from the local folder instead of using it from the url in jquery?

I am reloading the div every 30 seconds without reloading the whole page and also the user can see loading image when the refresh is happening meaning once the refresh starts it will gray the background and show the loading image and everything is working fine. 我每30秒重新加载一次div,而不重新加载整个页面,并且用户在刷新发生时可以看到正在加载图像,这意味着一旦刷新开始,它将使背景变灰并显示正在加载的图像,并且一切正常。

Below is the image I am using which is on this url - http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif 以下是我使用的图片,该图片位于此url- http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif

在此处输入图片说明

<script>
$(document).ready(function(){
    // Create overlay and append to body:
    $('<div id="overlay"/>').css({
        position: 'fixed',
        top: 0,
        left: 0,
        width: '100%',
        height: $(window).height() + 'px',
        opacity:0.4, 
        background: 'lightgray url(http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif) no-repeat center'
    }).hide().appendTo('body');

    // Execute refresh with interval:
    setInterval(refresh, 30 * 1000);
});
</script>

<script>
//Create a refresh function:
function refresh(){
    // SHOW overlay
    $('#overlay').show();
    // Retrieve data:
    $.ajax({
        url: 'dataInfo.jsp',
        type: 'GET',
        success: function(data){
            // onSuccess take only the container content
            var content =  $($.parseHTML(data)).filter(".container"); 
            //Replace content inside the div
            $('.container').replaceWith(content);
            // HIDE the overlay:
            $('#overlay').hide();
        }
    });
}
</script>

And below is my div which I am reloading every 30 seconds - 下面是我每30秒重新加载一次的div-

    <div class="container">
        <!-- some table here -->
    </div>

Now everything is working fine. 现在一切正常。 The only issue is when I will deploy this code in production, it will not work since I am using the image url as it is http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif which will get blocked in production because of firewall issue. 唯一的问题是,何时将此代码部署到生产环境中,由于我使用的图像网址为http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif ,因此无法使用由于防火墙问题,它将在生产中被阻止。

So to avoid this issue, I have downloaded the image locally in my webapp/resources/img folder in my project and now I am not sure how should I modify my code in such a way so that I can use the image from my local directory instead of using it from the URL directly? 因此,为避免发生此问题,我已将图像本地下载到项目中的webapp/resources/img文件夹中,现在不确定如何修改代码以便可以使用本地目录中的图像而不是直接从URL使用它?

I know I need to use img tag but how do I modify my code accordingly? 我知道我需要使用img标签,但是如何相应地修改代码?

Any example will be appreciated on this. 任何例子将不胜感激。

Just replace http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif with an absolute url. 只需将http://bradsknutson.com/wp-content/uploads/2013/04/page-loader.gif替换为absolute网址即可。 Change it to webapp/resources/img/page-loader.gif . 将其更改为webapp/resources/img/page-loader.gif Or you can put the file in the same directory as your page and simple use page-loader.gif , which is a relative url. 或者,您可以将该文件放在页面所在的目录中,并简单地使用page-loader.gif ,这是一个relative URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM