开发者

how to call python function using jquery?

i am learning python with GAE and for 开发者_StackOverflowinterface use jquery so i want to know calling python function using jquery.


jQuery runs in the browser, operates on the DOM tree and gets data from servers mostly through asynchronous HTTP requests. Python runs on the backend - in case of GAE on Google's infrastructure. So the way to call functions on the server from the client is by making requests.

$.get('ajax/test.html', function(data) {
    $('.result').html(data);
    alert('Load was performed.');
});

All you need for this to work is something on the server responding to a GET request to ajax/test.html - be it a static file or a Python function (e.g. a RequestHandler), which handles the request and returns some data.


Use AJAX!!

Define a webapp page using

class AjaxPage(webapp.RequestHandler):
    def get(self):
        result = your_function()
        self.response.out.write(str(result))

And call it through the page's url through ajax.


I believe you need to create a route for the app engine, and call that route with jQuery.

--EDIT-- The below turns out to be really really untrue, so don't mind it!!! I'm not going to remove it 'cause that would be lame. I have done some work with the Python SDK and tiny bit with the Java SDK, and doing so I felt the Python SDK was falling behind. More experienced programmers seem to disagree, hence this edit.

Have to warn you though, Google is focussing more on the Java platform than the Python platform; very often extra work is involved to achieve the same results as with Java, and sometimes things are simply unsupported.

What is your focus here? To learn Python or to learn Python with GAE?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜