hello,
all your CSS and JAVASripts files must be in the /static folder.
For the html, you can use it in the /static also, but the better way
is to use it as a template.
this example I made, that uses (JavaScript AJAX, CSS, and XML) can
help you to see how it works:

-----------------------------------------------------------------------------------------------------------------
# code.py
import web
import time
render = web.template.render('templates/')

urls = (
  '/', 'index',
  '/ajax', 'ajax')

class index:
    def GET(self):
        print render.index()

class ajax:
    def GET(self):
        time.sleep(3)
        print "<?xml version=\"1.0\"?>\n"
        print "<example>"
        print " <data>Hello World</data>"
        print " <data>AJAX is Working</data>"
        print " <data>Thanks</data>"
        print "</example>"

web.webapi.internalerror = web.debugerror
if __name__ == "__main__": web.run(urls, globals(), web.reloader)

-----------------------------------------------------------------------------------------------------------------
# ajax.js

function ajax()
{
    var xhr=null;

    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
    //on définit l'appel de la fonction au retour serveur
    xhr.onreadystatechange = function() { alert_ajax(xhr); };

    //on affiche le message d'acceuil
    document.getElementById("message").className="seeme";

    //on appelle le fichier reponse.txt
    xhr.open("GET", "ajax", true);
    xhr.send(null);
}

function alert_ajax(xhr)
{
    if (xhr.readyState==4)
    {
        var docXML= xhr.responseXML;
        var items = docXML.getElementsByTagName("data")
        //on fait juste une boucle sur chaque element "donnee" trouvé
        document.getElementById("message").className="notseeme";
        for (i=0;i<items.length;i++)
        {
                alert (items.item(i).firstChild.data);
        }
    }
}

-----------------------------------------------------------------------------------------------------------------
# example.css
.notseeme
{
 visibility: hidden;
}

.seeme
{
 visibility: visible;
 font-size : 200%;
 background-color: #DAEDFC;
 width: 300px;
 height: 40px;
}

-----------------------------------------------------------------------------------------------------------------
# index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="fr" lang="fr">
<head>
        <title>index</title>
        <link rel="stylesheet" href="/static/example.css" type="text/css" />
</head>

<body>
<script type="text/javascript" src="/static/ajax.js"></script>

<p>
<a href="javascript:ajax();">Request AJAX, GO!</a>
</p>

<div class="notseeme" id="message">Wait please...</div>
<p>Test the : AJAX HTTP-Get request in web.py .</p>

</body>
</html>

--------------

put the 'ajax.js' and 'example.css' in the /static folder,
and 'index.html' in the /template folder,
then run 'code.py'

I hope this will help you starting with.


dineshv wrote:
> I got my webpy website up and its all hanging together - great!  Next,
> I have to develop some Javascript code followed by Javascript with
> AJAX.  Before I start, is there any advice you can give wrt using
> webpy and Javascript/AJAX ie. do's, don'ts, best practice?  Thanks a
> lot!
>
> Dinesh
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to