Using IronPython in Umbraco – testing some Ajax

I just did some tests to spice up pyForum with Ajax. Still without any code but Python (well Javascript ofcourse). Here’s what I did:

I setup a Ajax call on the pyForum form posts to serialize the form and send it to the macro via Rndr (see separate post about that package if you like). Rndr activates on a url call and renders the pyForumStart macro with a query string that tells the macro to only handle post data. My Python code like this:

requestAjax = library.RequestQueryString("ajax")
requestId = library.RequestQueryString("id")

if requestAjax:
    if requestAjax == "getthreads":
        getlist = ForumThreadsHtml(int(requestId))
        print getlist
    if requestAjax == "post":
        post = HandleFormPost(None)
        print post
    print ForumStartView()

For my Javascript I added this string Html template:

includeJavascriptTemplate ="""
<script type="text/javascript">
function getForumThreads()
id = jQuery('#forumpost-id').val();
url = "" + id + "&rnd=" + Math.floor(Math.random()*10000000);
url: url,
type: 'GET',
success: function (data) {
error: function (msg, url, line) {
alert(msg); }
} );

function getDataFromMyMacro()

url = "";
data = jQuery('#forumpost').serialize();
url: url,
data : data,
type: 'POST',
success: function (data) {
error: function (msg, url, line) {
alert(msg); }
} );



A bit slow at first

When I tried out the Ajax-version of the form I was a bit disappointed at first, since each Ajax post took 2 X 0.4 seconds or something. But no surprise actually since every call to the web server do take some tenths of a second. So I changed from two Ajax calls to one. Of course it’s indeed how Ajax should be handled. Dont ever call twice if you can call once.

I remade the code a bit so I have one call – and it makes Ajax posting better.

Have a look at the current demo.

Some nice message and perhaps a fade would make the thing look even better.

Conclusion and progress

Yes, this “Ajax over Rndr + Python” method seem to be fast enough and worth taking a step further. So my next post will be on writing a complete Ajaxified version of pyForum. Including the packaged code. So keep watching this space.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s