How to call function in my python code on click button - from javascript onClick call Python
I'm trying to implement ajax on Che开发者_JAVA技巧rryPy site and I have problem. How to call function in my python code (function name: ajax_data is @cherrypy.expose and returns some json which I can easily processed ) on click button ( ) ? How to onClick to call ajax_data ? ( I looked first on Google but I find only when button is inside form tag and type submit, but I have table with data and last column is buttons which need to call ajax_data function in python ).
Ajax is initiated from Javascript in the the browser. I would recommend looking at Jquery and http://api.jquery.com/category/ajax/ and more specifically http://api.jquery.com/jQuery.getJSON/
Simple example JS Code or call to the back end (NOTE: you will need to include jquery before this is called):
$.getJSON('/ajax_data', function(data) {console.log(data)}
精彩评论