开发者

How to call function in my python code on click button - from javascript onClick call Python

开发者 https://www.devze.com 2023-03-08 20:11 出处:网络
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

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)}

0

精彩评论

暂无评论...
验证码 换一张
取 消