Skip to content

Instantly share code, notes, and snippets.

@JamesHovious
Last active August 29, 2015 14:16
Embed
What would you like to do?
from browser import document, ajax
#Ajax arguments
qs = ''
url = 'http://headers.jsontest.com/'
def post_data(url, qs):
req = ajax.ajax()
# Bind the complete State to the on_post_complete function
req.bind('complete',on_post_complete)
# send a POST request to the url
req.open('POST',url,True)
req.set_header('content-type','application/x-www-form-urlencoded')
# send data as a dictionary
req.send(qs)
def get_data(url, qs):
req = ajax.ajax()
req.bind('complete',on_get_complete)
# Bind the complete State to the on_get_complete function
req.open('GET', url+'?'+qs, True)
req.set_header('content-type', 'application/x-www-form-urlencoded')
req.send()
def on_post_complete(req):
if req.status==200 or req.status==0:
# Take our response and inject it into the html div with id='main'
document["main"].html = req.text
else:
document["main"].html = "error "+req.text
def on_get_complete(req):
if req.status==200 or req.status==0:
# Take our response and inject it into the html div with id='main'
document["main"].html = req.text
else:
document["main"].html = "error "+req.text
get_data(url, qs)
post_data(url, qs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment