简体   繁体   中英

How to get data from jQuery script (web.py)?

I can't find any tutorial for jQuery + web.py. So I've got basic question on POST method.

I've got jQuery script:

<script>
     jQuery('#continue').click(function() {
         var command = jQuery('#continue').attr('value');
         jQuery.ajax({
              type: "POST",
              data: {signal : command},
         });
     });
</script>

A simple form:

<form>
    <button type="submit">Cancel</button>
    <button type="submit" id="continue" value="next">Continue</button>
</form>

and python script:

def POST (self):
        s = signal
        print s
        return

I expect to see string "next" in console. But it doesn't happen.

I have a strong feeling that selectors somehow do not work. Any way to check it?

you need to use web.input in web.py to access POST variables

look at the docs: http://webpy.org/docs/0.3/api (search for "function input")

def POST(self):
    s = web.input().signal
    print s
    return
<script>
     jQuery('#continue').click(function() {
         var command = jQuery('#continue').attr('value');
         jQuery.ajax({
              type: "POST",
              data: {signal : command},
              url: "add the url here"
         });
     });
</script>

add the url of the server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM