No, I'm afraid neither
  s=get_buttons()
  return 'jQuery("#target").html("%s");' % s.replace('"','\\"')
nor
  return """jQuery("#target").html("%s");""" % (response.render
(s).replace('"','\\"'))
do anything. Nothing is rendered.

On Oct 11, 3:31 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
> What about using response.render() to create the html?
>
> This way you just have to write your html in your views?
>
> return """
> jQuery("#target").html("%s");
> """ % (response.render(form=form).replace('"','\\"'))
>
> -Thadeus
>
>
>
> On Sun, Oct 11, 2009 at 1:38 PM, mr.freeze <nat...@freezable.com> wrote:
>
> > Massimo's last suggestion should work as it will escape quotes in the
> > output.  Have you considered using jQuery.load to populate the
> > subsections?http://docs.jquery.com/Ajax/load#urldatacallback
>
> > On Oct 11, 1:31 pm, weheh <richard_gor...@verizon.net> wrote:
> > > I will try these suggestions but I doubt they will work as the
> > > javascript portions of get_page have both single and double quoted
> > > sections that probably can't be replaced without breaking the
> > > javascript.
>
> > > What's frustrating about jQuery and javascripted actions in context of
> > > web development in general, and in this case, my web2py app, is that
> > > they break the DRYness of my code. It seems like I always have to
> > > write one set of page-rendering code for the initial page generation,
> > > and then another set of html to generate the sub-sections of the page
> > > that will be created in response to a javascript event. I really want
> > > to render the different sections of the page from the same code at all
> > > times. Does anyone have any insights into how to structure your code
> > > to be DRY while still being able to pull off a page that can be
> > > generated in its entirety by a straight URL call or in pieces by ajax
> > > calls that target specific subsections of the page? It assumes a page
> > > that has all sorts of different kinds of things, including css
> > > widgets, straight html, and javascripts.
>
> > > On Oct 11, 2:02 pm, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > assuming s is valid html you can also try
> > > > 'jQuery("#target").html("%s");' % s.replace('"','\\"')
>
> > > > On Oct 11, 12:04 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
>
> > > > > I would think that your function, is returning a qoute of some sort,
> > which
> > > > > is canceling out the qoute around .html, which is throwing off the
> > > > > javascript errors.
>
> > > > > this
>
> > > > > 'jQuery("#target").html("%s");' % ('<strong class="hi"> this is a
> > strong
> > > > > sentence that breaks the javascript</strong')
>
> > > > > Notice the qoutes where it defines class=. Try  changing all double
> > qoutes
> > > > > to single qoutes, see if that fixes your problem.
>
> > > > > I ran into this as well, and single qoutes in the html fixed my
> > problem.
>
> > > > > -Thadeus
>
> > > > > On Sun, Oct 11, 2009 at 11:33 AM, weheh <richard_gor...@verizon.net>
> > wrote:
>
> > > > > > Massimo, I tried all your callbacks and none of them can render
> > > > > > get_page. I should have noted that get_page is the exact same
> > function
> > > > > > that I use to successfully render the sub-page initially when the
> > user
> > > > > > clicks on the link that takes them to this particular page.
>
> > > > > > That said, the text portion of get_page is rendered correctly by
> > the
> > > > > > following callbacks:
>
> > > > > >  return "jQuery('#target').html(%s);" % repr(text)
> > > > > >  return "jQuery('#target').html(%s);" % sj.dumps(str(text))
> > > > > > and this works, too, but ' is quoted \'
> > > > > >  return "jQuery('#target').html('%s');" % sj.dumps(repr(text))
>
> > > > > > I would never have thought to invoke sj.dumps to do the job of
> > > > > > rendering the text. I'm curious why this should even work?
>
> > > > > > get_page calls a function show_buttons() that generates the buttons
> > on
> > > > > > the page. These are rollover-type buttons with a sharethis button,
> > > > > > which is javascript. Taking, the divide and conquer approach to
> > > > > > debugging the problem, I also tried the following callbacks, with
> > the
> > > > > > results shown as comments below. None of the javascripts worked to
> > > > > > render the buttons.
>
> > > > > >  return "jQuery('#target').html(%s);" % show_buttons() #fails:
> > error
> > > > > > missing } in sharethis javascript
> > > > > >  return "jQuery('#target').html(%s);" % repr(show_buttons())
> > #fails:
> > > > > > nothing renders, error "missing = in XML attribute"
> > > > > >  return "jQuery('#target').html(%s);" %
> > sj.dumps(str(show_buttons()))
> > > > > > #fails: only sharethis button renders, but sharethis function not
> > > > > > defined when you click on the button. None of the css rollover
> > buttons
> > > > > > render. And rest of webpage is mysteriously cleared.
> > > > > >  return "jQuery('#target').html(%s);" % sj.dumps(repr(show_buttons
> > > > > > ())) #fails: Nothing renders, but target is cleared.
> > > > > >  return "jQuery('#target').html('%s');" % sj.dumps(str(show_buttons
> > > > > > ())) #fails: nothing renders, error: "missing ) after argument
> > list"
> > > > > >  return "jQuery('#target').html('%s');" %
> > sj.dumps(repr(show_buttons
> > > > > > ())) #fails: renders pair of double quotes "" in target div
> > > > > >  return 'jQuery("#target").html("%s");' % sj.dumps(str(show_buttons
> > > > > > ())) #fails: nothing renders, error: "missing ) after argument
> > list"
> > > > > >  return 'jQuery("#target").html("%s");' %
> > sj.dumps(repr(show_buttons
> > > > > > ())) #fails: nothing renders, error: "missing ) after argument
> > list"- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to