Last active
          August 29, 2015 14:16 
        
      - 
      
 - 
        
Save JamesHovious/40d26c84c8393932a845 to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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