1

I'm currently learning some jquery and javascript, I'm currently experimenting with a lot of stuff for our intranet systems, more or so converting some monitoring applications to web based applications.

One such Application involves having a menu list that changes background color dependent on activity, what I have done for this is loading a php page that generates the required status of each block and outputs it unto a list type format.

menu.php output

<ul>
 <a href="index.php?id=1"><li class="green">Menu 1</li></a>
 <a href="index.php?id=2"><li class="blue">Menu 2</li></a>
</ul> 

php code changes id and the class, based on the status of data on the specific Menu, now using jquery's setInterval function, I autorefresh the divs containing the menu on my index.php to change the background color of the links, these links btw refreshes the data on div table.

index.php

$(document).ready(function() {
$.ajaxSetup({ cache: false });
setInterval(function() {
$('menu').load('menu.php');
}, 10000);
});
// ]]></script>
<body>
<div id="menu>
Menu list Generated here
</div>
<div id="table">
Selected data
</div>
</body>

what im trying to do now is I want to also refresh the data of the table div, by implementing ajax, and utilizing a .load on click (from menu.php) and loading an table.php using something like the code below to avoid refreshing the whole page.

<a id="click" href="#">click</a>

<script>
    $(function() {
      $("#click").click(function(evt) {
         $("#table").div().load("table.php")
         evt.preventDefault();
      })
    })
</script>  

and it seems it is not working this time, from what I am seeing maybe it is not possible for the link on menu.php, to update the div on my index.php which is #table. hence my question

or maybe I'm doing this all wrong, any insights on what would be a better approach maybe?

  • You need to load - ``.load()`` results into valid element on the page that would be the first here. Maybe you forgot specify that that's a class or id. And on the click one as i recall there's not ``.div()`` method in jQuery. – arma Apr 04 '14 at 04:08
  • Please check this . Sometimes will be helpful http://stackoverflow.com/questions/18490026/refresh-reload-the-content-in-div-using-jquery-ajax – Mad Angle Apr 04 '14 at 04:13
  • possible duplicate of [Load content of a div on another page](http://stackoverflow.com/questions/4101770/load-content-of-a-div-on-another-page) – Brian North Apr 04 '14 at 04:31
  • actually it was a stupid part on my side, I messed up on not adding the jquery.js on menu.php, it works as intended now, thanks all! – user3496322 Apr 04 '14 at 06:03

0 Answers0