Winterwind
Winterwind

Reputation: 117

Adding AJAX call on each page

So, I'm new to AJAX and I'm not sure how I will do this, but I have three different pages and I would like to add AJAX call to all of them and everything inside of those files.

I guess the page would start with something like:

$(document).ready(function(){
    setInterval(function(){
        $('').load('target.php');
    );
});

Not sure if that's a start or not? I'm quite a newbie, so if I forgot any information please tell me and I will try to edit the first post.

I would like to add the call when you click a menu.
EDIT:
<?php

echo "

      <li><a href='gestbookk.php'>Woodland</a></li>
         <li><a href='fileupload.php'>Hem</a></li>
         <li><a href='laddaupp.php'>Mountains</a></li>


";

?>

This one is included to all pages.So the AJAX call starts when clicking on one of the menu links.

Upvotes: 0

Views: 71

Answers (2)

user3232725
user3232725

Reputation: 218

in that case you need something more or less like this:

  $(document).ready(function()
 {
   $('li a').click(function(){
        $.get($(this).prop('href'), function(data){
            $('#CONTENTHERE').html(data);
        });
        return false;
    });
 });

$('') => Doesnt make that much sense, neither does the set interval(Jquery allso has build in timers)

this would prolly be something you are looking for:

$(document).ready(function()
{
  $.get('target.php', function(data){
//we are done add this to our body
    $(body).append(data);
  });
  $.get('target2.php', function(data){
//we are done add this to our body
    $(body).append(data);
  });
  $.get('target3.php', function(data){
//we are done add this to our body
    $(body).append(data);
  });
});

Upvotes: 1

RGS
RGS

Reputation: 5211

<script>
   $(document).ready(function(){
     setInterval(function(){
     $('').load('target.php');

       }, 1000);

   });
 </script>

Upvotes: 0

Related Questions