Home >  Archive >  2011 >  December >  19

Previous / Next

Question re jQuery/JavaScript
By Dave Winer on Monday, December 19, 2011 at 10:04 AM.

I hit a problem yesterday in the interaction between jQuery and JavaScript, I think. It's time to ask the Scripting News brain trust to help me figure out what I'm doing wrong.  #

Here's the page in question. Suggest you View Source. #

Search for the call to sendToLinkblog. I've pasted the text in below#

<li><a title="Send to linkblog." onclick="sendToLinkblog('${escapeParam(item.body)}', '${escapeParam(item.link)}', '${escapeParam(item.title)}')">RT</a></li> #

escapeParam is doing its job correctly on item.title, but not on item.body. I can see this by looking in Firebug, as well as in the behavior of the app. Calls to sendToLinkblog for items that have one or more single-quotes in their title fail, presumably because of a syntax error, due to the unescaped single-quotes. #

So the question is this -- why does the call work for item.body and not for item.title? #

I thought perhaps it was a type issue, that they weren't all strings, but I can't figure out what else they might be. #

For an experienced JS developer I'm sure this would be easy.  #

Thanks in advance for your help! :-) #

Update: Problem solved, though no one person had the answer. Nik Cubrilovic suggested adding a call to "escape" at the beginning of the escapeParam routine. But this just had the effect of doubly-encoding the params, and didn't solve what was clearly a syntax problem in the call to sendToLinkBlog. However, it gave me an idea. I could do the URL-encoding in the call to sendToLinkBlog, and solve the single-quote escaping problem, and eliminate the escaping in sendToLinkBlog. Bing! It worked. So now I'm ready to move on to the next problem/bug. Thanks as usual for the brain-trust help. #




This site contributes to the scripting.com community river.


© Copyright 1997-2011 Dave Winer. Last update: Monday, December 19, 2011 at 11:34 AM Eastern. Last build: 12/31/2011; 10:01:49 AM. "It's even worse than it appears."

RSS feed for Scripting News

Previous / Next