On Aug 5, 8:51 am, matt barto <matt.ba...@gmail.com> wrote: > Hello, > > I am attempting my first ajax page to no avail. My goal is to have a > form with a text box and upon submission I will append all the text to > the html. Here is the javascript leveraging jquery. > > $(document).ready(function() { > $('#submit').submit(function () { > $('#content').append('Sending Message!'); > var msg = $("input[name='comment']").val(); > $.ajax({ > type: "GET", > url: "/home/", > data: msg, > dataType: "xml", > error: function() { > alert('Error loading data'); > }, > success: function(xml) { > alert('Success loading data'); > $('#content').append('success'); > var time = $(xml).find('time').text(); > var msg = $(xml).find('message').text(); > > $('#content').append(msg); > } > }); //close $.ajax > }); //close click > > }); //close ready > > In views I am making an xml document and returning it: > > return HttpResponse( doc.toprettyxml() , mimetype = "text/xml" ) > > The problem I am seeing is that the xml will be returned and be > displayed only when I am expecting the ajax success function to handle > the xml and update the html page. The result page is: > > This XML file does not appear to have any style information associated > with it. The document tree is shown below. > > - > <wml> > <time> > August 05 Wednesday 2009 07:45AM > </time> > <message> > howdy > </message> > </wml> > > Can someone please help me understand what I am missing? More code > can be provided, but I only tried to give what I thought was > relevant. I appreciate any feedback! > > -Matt
This isn't a Django question, and you haven't really explained what the problem is, but one obvious thing that jumps out is that you're not preventing the form submit from actually happening. So the AJAX runs, does what it should, but then the page immediately submits and refreshes as normal. You need to make your submit() function take an 'event' parameter and then somewhere in that function do event.preventDefault();. -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---