Ajax question

I have a page that uses a bit of Ajax. Basically it pulls links from a db and then post these links on the fly. It also paginates these links so it looks tidy. My question is, is there a way for me to write a function that’ll load the first query onload so that these links are rendered in the html for google search purposes?

Anything “rendered” with javascript will not be seen by google. Put the first set of links in the html server-side, using php or something like that. If you disable javascript in your browser, then visit your page, you will see what google “sees” when it crawls your page.

I’m sure I can load the first set of links in the html somehow. I gotta figure out something clever…

A good solution is to simply include the list (full or just the first page) in the HTML sent to the browser/Google, and use progressive enhancement to allow users with Javascript enabled to load alternative pages. Google and users without JS will be stuck on the first page, but this seems fine within the circumstances.

So you’re saying just send a static page of the links? What’s progressive enhancement? Excuse my newb-ness.

Send a page with the static links, and then through Javascript add buttons and functionality to navigate to the other sets of links. If you choose to send only the first page of links statically, you’ll just need to add the pagination functionality; if you choose to send it all statically, you’ll need to remove all of the links through Javascript except those on the first page, and then add the pagination functionality.

So, to Google and a user without Javascript, they’ll still see the links sent statically, without any pagination functionality, but users with Javascript will get an enhanced version with the functionality.

Thank you for the insight. Ill give it a whirl as soon as I get some free time. It makes sense to just turn off JS and then get a sitemap created for it. I thought I would have to do something onload. Ill let you know how it goes.

Think of it like this… if you really want to cover all your bases then design a website with absolutely no javascript. Test it and make sure your website is fully functional. Then, when you’re done with that, go back and write javascript code to “intercept” the functionality of your website. That probably sounds a bit cryptic, but here’s a practical example:

You have a link and when a user clicks that link, you would like to have a paragraph of text loaded into a div. So, you write something like this:


<a id="my_link" href="/index.php?show_paragraph=1">My Link</a>

And the PHP may be…


...
<div>
if(isset($_GET['show_paragraph']) && $_GET['show_paragraph'])) {
  echo $my_paragraph_text;
}
</div>
...

Fair enough… but you’ve had the buzzword “Ajax” rammed in your ear for the last couple of years, and you’d rather load the paragraph into the div utilizing this technique (and why wouldn’t you?.. ajax is cool). So, now you could do something like this:


<script language="javascript" type="text/javascript">
<!--
  window.onload = function()
  {
    addEvent(document.getElementById('my_link'), 'click', function()
    {
      // send and ajax request to retrieve your paragraph
      return(false);  // this keeps the browser from actually sending the http request
    }

    function addEvent(o, type, func, prop)
    {
      if(!o) {
        return;
      }

      if(!document.addEventListener && document.attachEvent) {
        o.attachEvent("on" + type, func);
      } else {
        o.addEventListener(type, func, prop);
      }

    }
  }
-->
</script>

Of course, the bit about “making an ajax call” will be more complex, but is beyond the scope what I’m trying to say. This overcomes one of the several problems with the heavy use of ajax… search engine indexing. If you do this with all of your ajax code you no longer have to worry about your pages not being indexed because you can see all of the content on your webpage whether javascript is enabled or not.

Now all you have to overcome is the issue with the browser history not working and not being able to bookmark pages. :slight_smile: (which both have solutions…)

You are brillant man. I was nearly pulling out my hair trying to figure it out. From what i read in your coding, it makes sense.

In other words, progressive enhancement. This is the same idea I was trying to suggest above: give the content without Javascript, and then add the enhanced pagination behavior with JS.