Webpy with jQuery for AJAX

802 views
Skip to first unread message

Dexter

unread,
Sep 28, 2011, 1:28:31 PM9/28/11
to web.py
Hi

Have been trying to implement some AJAX using jQuery.
Have referred to this for some directions
http://kooneiform.wordpress.com/2010/02/28/python-and-ajax-for-beginners-with-webpy-and-jquery/

Basically what I want to do is as a proof of concept is receive some
data from a server and display it on a page.


Server side file simply returns "Ajax Data" when called with POST

code.py
-----------------------------

class tabs:
def POST(self,*args):
return "Ajax Data"
--------------------------------------------------------


Client Side - The code below should receive "Ajax Data" text from
server after clicking #button and display it in sandbox area which is
a div
--------------------------------------------------------
jQuery("#button").click(function() {
$.ajax({
type: 'POST',
data: 'dummy'
success: function(data) {
alert(data); /*Debugging Statement*/
jQuery('#sandbox').html(data);
},
});
return false;
});

However nothing happens. When I added an alert to see what is being
returned. The alert Box displays
[object XMLDocument] while I was expecting a string.

What did I do wrong ?




Dexter

unread,
Sep 28, 2011, 3:09:33 PM9/28/11
to web.py
Solved.
Firefox was treating the reply as XML
Added web.header("Content-Type", "text/plain")
and issue gone :)


On Sep 28, 10:28 pm, Dexter <sci.cr...@gmail.com> wrote:
> Hi
>
> Have been trying to implement some AJAX using jQuery.
> Have referred to this for some directionshttp://kooneiform.wordpress.com/2010/02/28/python-and-ajax-for-beginn...

Bruce Eckel

unread,
Sep 29, 2011, 1:43:22 PM9/29/11
to we...@googlegroups.com
I'll be publishing a web post on this very subject in the next couple of days. I'll put a link to it on this group when I do.

-- Bruce Eckel
www.Reinventing-Business.com
www.MindviewInc.com







--
You received this message because you are subscribed to the Google Groups "web.py" group.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.


Bruce Eckel

unread,
Sep 30, 2011, 6:03:03 PM9/30/11
to we...@googlegroups.com

michael kapelko

unread,
Sep 30, 2011, 11:03:20 PM9/30/11
to we...@googlegroups.com
Very nice article.
I always wondered how to make a user application with web interface,
and it's just webbrowser module!
There's one misprint where you refer to num as sum: "... while sum is
generated with JavaScript's random number generator ...".

PS.

I've just read you're Bruce Eckel who wrote "Thinking in C++". It was
very nice, I started with it! I must say it's the only book I've read
most completely about C++ :)
I also remember reading "Thinking in Java" when I had a course about
Java if I'm not mistaken.

Bruce Eckel

unread,
Oct 1, 2011, 8:28:56 AM10/1/11
to we...@googlegroups.com
Thanks for the typo fix!

redfish

unread,
Oct 29, 2012, 10:13:29 PM10/29/12
to we...@googlegroups.com
good job .very nice article. It solves my problem

在 2011年10月1日星期六UTC+8上午6时03分03秒,Bruce Eckel写道:
Reply all
Reply to author
Forward
0 new messages