Advertisement
simbha

GAE ajax

Nov 25th, 2013
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 KB | None | 0 0
  1. GAE ajax
  2. clone : http://pastebin.com/CAceZLDK
  3. in response : http://stackoverflow.com/questions/19250831/python-gae-render-an-image-returned-from-ajax-post-json-format#comment28537691_19251636
  4.  
  5. http://stackoverflow.com/q/19250831/2541442
  6.  
  7. # main.py
  8.  
  9. class DoubleNumbers(webapp2.RequestHandler):
  10.         def get(self):
  11.                 pass
  12.                
  13.         def post(self):
  14.                 #self.response.headers['Content-Type'] = 'application/json'
  15.                 data = json.loads( self.request.body )
  16.                 z = data['imageSrc']
  17.                 logging.info(z)
  18.                 self.response.write(z)
  19.  
  20.  
  21.  
  22.  
  23.  
  24. # JS
  25.  
  26. $(document).ready(function() {
  27.         $("button").click( function(){
  28.                
  29.                 console.log("PRESS");
  30.                
  31.                 var data = { 'imageSrc' : 'https://www.google.com.br/images/srpr/logo6w.png' };
  32.                            
  33.                 var request = $.ajax( { cache: false,
  34.                                                                 url: "/i",
  35.                                                                 type: "POST",
  36.                                                                 data: JSON.stringify(data),
  37.                                                                 //dataType: "json"
  38.                 }).done( function(data){
  39.                         var txt = "<!DOCTYPE html><html><body><img src='"+data+"'></body></html>";
  40.                         document.open("text/html");
  41.                         document.write( txt );
  42.                         document.close();
  43.                         console.log(data);
  44.                         console.log(txt);
  45.                 });
  46.                
  47.         });
  48. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement