23 November 2005

Ajax without XmlHttpRequest

Posted by Mikhail Esteves under: AJAX; LAMP; Tips .

PHPit has an interesting idea:

engine.js

// Get base url
url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);

function ajax_do (url) {
        // Does URL begin with http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }

        // Create new JS element
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        // Append JS element (therefore executing the 'AJAX' call)
        document.body.appendChild (jsel);
}

test.php

<html>
<head><title>Demo 1 - The Basic's</title>
  < script type="text/javascript" src="engine.js">       
</head>
<body>
  <div id="contentdiv"></div>
  <input type="button" onclick="ajax_do ('page1.php');" value="Get content" />
</body>
</html>

You can see the demo here

Technorati Tags , , , , , ,


One Comment so far...

rascunho » Blog Archive » links for 2007-04-24 Says:

25 April 2007 at 1:38 am.

[…] the jackol’s den » Ajax without XmlHttpRequest – Mikhail Esteves (tags: http://www.thejackol.com 2007 ajax cross_domain code) […]

Leave a Reply

Browse

Photography

Projects

Pages

Calendar

November 2005
M T W T F S S
« Oct   Dec »
 123456
78910111213
14151617181920
21222324252627
282930  

Categories

www.flickr.com

Use OpenDNS