AlexNasonov
AlexNasonov

Reputation: 607

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?

Upvotes: 0

Views: 3554

Answers (2)

lig
lig

Reputation: 3910

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

Upvotes: 4

dku.rajkumar
dku.rajkumar

Reputation: 18588

<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.

Upvotes: 0

Related Questions