Ajax POST returning render_template in Flask?
this will help you
!DOCTYPE html> <html> <head> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> </head> <body> <script type="text/javascript"> $(function(){ var json = { 'foo': 1, 'bar': 2 } $.ajax('entry', { url='type url here', type: 'POST', dataType='json', data: JSON.stringify(json), contentType: 'application/json', success: function(data, textStatus, jqXHR){ console.log(data); }, error: function(jqXHR, textStatus, errorThrown){ console.log(errorThrown); } }); }); </script> </body> </html>
at back end receive data like this way
variable=request.get_json()
now variable is dict
I think this will help you
give this code a try:
<!DOCTYPE html><html><head> <title></title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script></head><body> <script type="text/javascript"> $(function(){ var json = { 'foo': 1, 'bar': 2 } $.ajax('entry', { type: 'POST', data: JSON.stringify(json), contentType: 'application/json', success: function(data, textStatus, jqXHR){ document.write(data); }, error: function(jqXHR, textStatus, errorThrown){ console.log(errorThrown); } }); }); </script></body></html>
http://www.w3schools.com/js/js_htmldom_html.asp
Hope this helps!