On Oct 5, 8:02 pm, Benjamin Goudey <[email protected]> wrote:
> I'm trying to figure out how to use web.py and JQuery together and I
> found a neat example posted by jgfoot last year on how to do this. But
> I can't seem to get it to work the way I think it should. My
> understanding is that the
> #riverName paragraph should get filled with the river corresponding to
> the city. But this doesn't happen for me. But I do know that it is
> retrieving the river name as it prints to stderr. Can anyone shed any
> light on why this isn't behaving as I think it should or if there are
> better ways on combining web.py and JQuery (or any Ajax-y type thing)
>
> Cheers
>   Ben
>
> ###################################
> ./river.py:
> ###################################
>
> import web
> import sys
>
> # A sample "database" using just a Python dictionary object
> database = {
>     "Tokyo" : "Sumida",
>     "Paris" : "Seine",
>     "Minneapolis" : "Mississippi",
>     "Manaus" : "Amazon",
>     "Cairo" : "Nile",
>     "Beijing" : "Yangtze",
>     "Seoul" : "Han" }
>
> class river:
>     def GET(self, cityName):
>         response = database.get(cityName, "I don't know")
>         sys.stderr.write(repr(response)+"\n") # a poor man's JSON
> converter

class river:
    def GET(self, cityName):
        response = database.get(cityName, "I don't know")
        sys.stderr.write(repr(response)+"\n")
        return response

maybe you should return the result!!
do you??

>
> web.application( ('/river/(.*)', 'river') , globals()).run()
>
> ############################
> /static/index.html:
> ############################
>
> <html>
> <head>
> <title>City to river</title>
> <script src="/static/jquery-1.2.3.js"></script>
> <script type="text/javascript">
>
> function lookupRiver() {
>     var whatTheUserEntered = $("#cityName").val();
>     $.getJSON("/river/" + whatTheUserEntered, function(data){
>       $("#riverName").html(data);
>     });
>
> }
>
> $(document).ready(function(){
>     $("#doLookup").click(lookupRiver);
>
> });
>
> </script>
> </head>
> <body>
> <p>Enter the name of a city:</p>
> <input id="cityName" />
> <input type="submit" value="Go" id="doLookup" />
> <p id="riverName"></p>
> </body>
> </html>
>
> ##############################################
--~--~---------~--~----~------------~-------~--~----~
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