Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

The JavaScript code you are sending (as seen by using print $response) is:

$('override_...').innerHTML="<a href='#' onClick='javascript:makeForm( +"...", "...", "...");'>...</a>';

but it should be

$('override_...').innerHTML="<a href='#' onClick='javascript:makeForm( +\"...\", \"...\", \"...\");'>...</a>";

The first double-quote is wrongly closed with a single quote, and you have unescaped double-quotes.

Other potential problems:

  • Is $('override_123') valid JavaScript? I've never seen that syntax before, but I have little JavaScript experience.
  • Are $componentId, $componentType and $newTitle properly escaped to be used in a JavaScript double-quoted string? (\ => \\, " => \")
  • Are $componentId, $componentType and $newTitle properly escaped to be used in an HTML single-quoted value? (& => &amp;, ' => &#39;)
  • Is $newTitle properly escaped to be used in HTML? (& => &amp;, < => &lt;)

Update: The following addresses quoting issues:

use strict; use warnings; use HTML::Entities qw( encode_entities ); sub js_from_text { for (@_ ? $_[0] : $_) { s/([\\"])/\\$1/g; return qq{"$_"}; } } sub html_from_text { for (@_ ? $_[0] : $_) { return encode_entities($_); } } my ($text_componentId, $text_componentType, $text_newTitle) = ...; my $js_component = js_from_text("override_$text_componentId"); my $js_componentId = js_from_text($text_componentId); my $js_componentType = js_from_text($text_componentType); my $js_newTitle = js_from_text($text_newTitle); my $js_onClick = "makeForm($js_componentId, $js_componentType, $ +js_newTitle);"; my $html_onClick = html_from_text($js_onClick); my $html_newTitle = html_from_text($text_newTitle); my $html = qq{<a href="#" onClick="javascript:$html_onClic +k">$html_newTitle</a>}; my $js_html = js_from_text($html); my $js_response = "\$($js_component).innerHTML = $js_html;"; print("$js_response\n");

There is a situation where hungarian notation is very useful. Making Wrong Code Look Wrong is a worthwhile read.

In reply to Re: formatting response text for AJAX widget by ikegami
in thread [OT?] formatting response text for AJAX widget by geektron

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others perusing the Monastery: (2)
    As of 2020-02-22 10:40 GMT
    Find Nodes?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?

      Results (99 votes). Check out past polls.