Michael, Whenever passing free form text, to prevent my app from choking on special characters, I wrap the variables that could have special characters in encodeURIComponent(textparam1) ... seems to work nicely. Your thoughts? -Mark
On 5/24/07, Michael Peters <[EMAIL PROTECTED]> wrote: > > > sughosh wrote: > > > var objHash = new Hash({}); > > objHash.merge({ qpName:settings.qpName, > > dbName:settings.dbName,userId:settings.userId,folderId:settings.folderId > }); > > objHash.merge({subject:$('subject01').value}); > > objHash.merge({body:body}); > > objHash.merge({parentUNID:parentThread}); > > objHash.merge({mainPostId:mainPost}); > > var pars = objHash.toJSON(); > > This is a very inefficient way to write it. Try this instead: > > var objHash = { > qpName : settings.qpName, > dbName : settings.dbName, > userId : settings.userId, > folderId : settings.folderI, > subject : $('subject01').value, > body : body, > parentUNID : parentThread, > mainPostId : mainPost > }; > var pars = $H(objHash).toJSON(); > > It avoids the overhead of all those merge calls and is more declarative. > But > even then, it's not quite the right way to pass post arguments. > > > var url = '/servlet/CreateDiscussionThread'; > > new Ajax.Request(url, > {method:'post',contentType:'application/x-www- > > form- > > urlencoded',encoding:'ISO-8859-1',onSuccess:this.handleResponse > ,postBody:pars}); > > Why are you using 'ISO-8859-1' and not utf8? Also, why are you turning > your name > value pairs into JSON and putting them into the post body? Why not just > send > them as arguments for the POST itself? > > new Ajax.Request(url, { > method : 'post', > parameters : objHash > }); > > Then Prototype will take care of encoding each key and value of the hash > you're > passing. > > -- > Michael Peters > Developer > Plus Three, LP > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---