Forum Moderators: open

Message Too Old, No Replies

Is it possible for AJAX to put HTML that shows up in the source?

With XMLHttpRequest?

         

supercyberbob

11:25 pm on Mar 5, 2011 (gmt 0)

10+ Year Member



Hi there.

I have 0 AJAX experience and can't code anything from scratch so bear with me.

Basically I need AJAX to call a PHP file and the output needs to show up in the source.

Why? I have implemented a caching plugin for Wordpress and I need some existing php snippets in the sidebar to stay dynamic, BUT, they need to show up in the source for googlebot etc.

So, simple example would be something like this...


<script language="javascript" type="text/javascript">

XMLHttpRequest /example.php

</script>


And example.php would be


<?php
$myString = "<div id="aaa">Hello!</div>";
echo $myString;
echo "<div id="bbb">I love using PHP!</div>";
?>


And all that html needs to show up in the source code. This might be possible with just AJAX I realize, but I would like to keep my php code intact and not mess with AJAX.

Possible? If so, would anybody be so kind as to provide the proper code for the AJAX bit. I haven't been able to find any working example on the net thus far.

Thanks for your time.

g1smd

11:28 pm on Mar 5, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



AJAX delivers content via Javascript which runs in the browser.

If you want it to show in the HTML source, the PHP script will have to put it there.

supercyberbob

12:03 am on Mar 6, 2011 (gmt 0)

10+ Year Member



Gotcha.

Thanks for the reply g1smd.