Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts

    Reloading a div without calling an external page

    I have a dashboard set up to automatically refresh the page and data. I want to move away from that and only refresh divs. The only issue is that the data i am calling is from the back end and not a separate file. I have the following code:

    Code:
     <script>
    var auto_refresh = setInterval(
    function()
    {
    $('#test_refresh').fadeOut('slow').fadeIn("slow");
    }, 10000);
    </script>
    PHP Code:
    <a href="#">Year to Date Sales<span id="test_refresh"> $<?=$this->YTDsales?></span></a>
    Obviously the data is not refreshing, it's more or less of an effect. Is there a way to just refresh single php data? Thanks for any help.

  • #2
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    Update: This seems to be working, but now once it fades back in, withing 3 seconds it disappears.

    Code:
    var auto_refresh = setInterval(
    function(request) 
    {
        $('#test_1').fadeOut('slow').load("/index/ #test_1").fadeIn("slow");
        //$('#test_2').fadeOut('slow').fadeIn("slow");
        //$('#test_3').fadeOut('slow').fadeIn("slow");
        //$('#test_4').fadeOut('slow').fadeIn("slow");
    }, 50000);
    Is there a reason that is happening?

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    what is the path of the page where that script appears?
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #4
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    It's the same page. It's the index page. If it helps I am on the Zend framework so I do have a controller running the php. Let me know if you need more information. Thanks.

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,448
    Thanks
    11
    Thanked 598 Times in 578 Posts
    as i suspected... jQuery might be too smart for it's own good, executing the script tags on index and re-hiding your content. That's the big reasons i don't use load(), even though it looks really handy. You might try a injection script i posted here, it is much like $.load but without as many side-effects and security risks. Other than that, there's nothing jumping out in your code at me as being wrong. I would post the rest of the page, stripped down to just show the problem, if that script doesn't go your way, and we can all take another look.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • Users who have thanked rnd me for this post:

    jcdevelopment (02-25-2014)

  • #6
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    I decided to go a different route as well. Read a lot about how load can give issues. Below is something else that I thought would help, but once again nothing seems to be happening. In fact I get an error now of: Error: $ is not defined. Which makes no sense. Below is the full code, hopefully someone can see a mistake somewhere.

    Code:
     $(document).ready(function () {
        var interval = 10000;   
        var refresh = function() {
            $.ajax({
                url: "/index/",
                cache: false,
                success: function(html) {
                    $('#test_1').fadeOut('slow').html(html).fadeIn("slow");
                    setTimeout(function() {
                        refresh();
                    }, interval);
                }
            });
        };
        refresh();
    });
    PHP Code:
    <a href="#">Year to Date Sales<span > <div id="test_1">$<?=$this->YTDsales?></div></span></a>


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •