1

firstly i understand that there are many questions on here about the same subject and yes i have read most of them, unfortunately i just cant seem to process the information to make it work,so i was hoping someone could possibly point me in the right direction to help me solve my issue out??

firstly the set up of the directories of my site, i have all different sections that are 'included' amongst each other to keep my site more simple when changes are needed, but my point is.. in my overall footer.php page i have 2 just before the tag they are

<script type="text/javascript" src="jquery/jquery-1.9.0.js"></script>
<script type="text/javascript" src="js/general.js"></script>

the general.js file is from a tutorial i seen which made it alot easier to have all the things in the same one place of there own.

So what i want is to refresh/reload a div id="menu_bar" with a navin which is for my menu at the top of the screen, on there i have a inbox system set up and that is the reason i would like to have this auto refresh, so it will basically show me i have a message instead of me just pressing F5 to check. plus i plan making a notification system and im guessing this would be an appropriate way to show that i have notifications... So as im very very VERY new to jquery, AJAX and most other things this stuff doesnt make too much sense, i get a bit, but still... so the code i have seem to put together from a variety of tutorials and here is what ive got ...

$(document).ready( function(){
$('#menu_bar').load('includes/menu.php');
refresh();
});

function refresh()
{
setInterval( function() {
    $('#menu_bar').fadeOut('slow').load('includes/menu.php').fadeIn('slow');
    refresh();
}, 3000);
}

So can someone help me by showing where ive gone wrong and WHY ive gone wrong so i can try to understand where i went wrong and how i should fix it? cheers

  • 5
    for starters try `.load` instead of `.loud` :) – Milo Wielondek May 10 '13 at 12:34
  • Can you show or tell us what happens with the code you entered here? Except the loud/load problem and the fact that you should not use refresh() in a setInterval, what problems do you have? – Tallmaris May 10 '13 at 12:41
  • Also `.fadeOut` instead of `.fadeout` :) – vijay May 10 '13 at 12:41
  • @Tallmaris -literally nothing happens, i dnt get error messages or anything, so im starting to wonder have i even got the thing connected properly as if its not working then i should be getting some sort of error ?? – user2188631 May 10 '13 at 13:09
  • Any error in the debugger? something like chrome console or firebug for firefox could help see what happens. Also, does it load at least the first time? – Tallmaris May 10 '13 at 13:13
  • ye i realised once i sent it i didn't check chrome console!.. firstly though ye it loads one i clicked f5 the paged loaded fine the first time and everything worked fine, it just didn't reload again.. – user2188631 May 10 '13 at 13:22
  • secondly the console says - "Uncaught ReferenceError: $ is not defined" - "Uncaught SyntaxError: Unexpected token < " – user2188631 May 10 '13 at 13:24
  • the "Uncaught ReferenceError: $ is not defined" has a sub error 'thing' saying "(anonymous function)" – user2188631 May 10 '13 at 13:25
  • ive got rid of the code for now and just tried something so simple.. i used alert('working'); to just make sure things are working and they are.. to a point... i get a syntax error in jquery-1.9.0.js:1 when i click that it takes me to the code for that specific page and what is highlighted is would you have any ideas why this would be saying that? – user2188631 May 10 '13 at 14:28

1 Answers1

0

You shouldn't call refresh() inside the setInterval function,or use setTimeout instead

mguimard
  • 1,881
  • 13
  • 14
  • does setTimeout constantly update? ive read a few things and it seems that the setTimeout refreshes the once? – user2188631 May 10 '13 at 12:51
  • Right, setTimeout will call the function once, you'll need to call refresh() in the setTimeout function. If you're using setInterval, don't call refresh(), the function will be executed every 3000ms in your example – mguimard May 10 '13 at 13:01
  • well in your opinion what would you advise would be the best one to use? – user2188631 May 10 '13 at 13:20
  • I would use setInterval, for readability. Have a look at answers on this topic, it could help you with that : http://stackoverflow.com/questions/729921/settimeout-or-setinterval – mguimard May 10 '13 at 13:32