开发者

write python inside jquery

I have a web2py application and am using jQuery to validate data. I want to write Python code inside jQuery. How can I do that?

if($("#myform_parent_id")[0].value != '' 
    && $("#myform_parent_birthdate")[0].value != ''
    &开发者_开发百科amp;& 
      // Here I want to write Python code
  ..
}

Because when i make this code inside controller and then return the form it is reset selected values.


If you define this code in the view (instead of the controller) then you can use Python code within {{ }} blocks.


Silverlight allows you to embed Python as a scripting language on the client-side. http://www.voidspace.org.uk/ironpython/silverlight/index.shtml


As no browser will understand Python, you'll have to make an Ajax call to the server if you really want to use Python. This will probably complicate things for you, if only as Ajax calls are asynchronous by definition. But jQuery does support it.

Alternatively, to keep it all within the browser, you need JavaScript-only. If you can't translate your Python to JavaScript yourself, you could take a look at automated conversions.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜