My Projects
Search Blog

Categories
Archives
Photo Albums
RSS

Powered by
BlogCFM v1.15

18 February 2006
Getting CFAJAX to handle Safari properly

The following applies to CFAJAX version 1.3.  I don't know about previous versions, and I certainly don't know about future versions!

I've noticed that CFAJAX seems to have with Safari. I've also noticed that other people have noticed as well.

Although my chat room worked for Safari users, Safari seemed to urlencode the parameters, and cf did not decode them.  Almost as if Safari URL encoded the parameters, and then URL encoded the whole XML packet.. so when coldfusion received the XML packet, it URL decoded it, and the parameters were still urlencoded.  Crazy!

So a safari user would type "hey just checking this out", and it would get passed to my functions as "hey%20just%20checking%20this%20out".

Here's my solution to this problem:

In the "convertDataPassedToCFFunctionParam" function, around line 90ish, just after the <cfelse> tag, I replaced the single line that was there (that starts with <cfset variable.param = listAppend ... >) with the following:

<cfif lcase(cgi.HTTP_USER_AGENT) contains "safari">
<cfset variables.param = ListAppend(variables.param,"""" & URLDecode(Replace(Replace(mid(variables.var, variables.firstPos+1 , len(variables.var)-variables.firstPos),Chr(34),"#Chr(34)##Chr(34)#","ALL"),Chr(35),"#Chr(35)##Chr(35)#","ALL")) & """")>
<cfelse>
<cfset variables.param = ListAppend(variables.param,"""" & Replace(Replace(mid(variables.var, variables.firstPos+1 , len(variables.var)-variables.firstPos),Chr(34),"#Chr(34)##Chr(34)#","ALL"),Chr(35),"#Chr(35)##Chr(35)#","ALL") & """")>
</cfif>


Basically, if the browser is safari, URLDecode the parameter value before placing it into the list. Otherwise, don't.

Posted by rickroot at 4:58 PM | Link | 1 comment
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Getting CFAJAX to handle Safari properly
I also URLDecode() all parameters passed to my ajax handler functions. Safari and CFAJAX handles URL encoding a different than IE and FF.

In somewhat older versions of CFAJAX - Safari browsers were force to use the GET method in the DWREngine._sendData() method. This worked with Safari ~1.5 but not with ~2.0. In order to work with both 1.5 and 2.0 with my complex ajax calls I force it to use the POST.

I also modified the engine.js code to carry through tokenized queries (i.e. ?CFID=xxx&CFTOKEN=xxx) in all the batch.req.open() calls...
The calls automatically append a "?" + query to without regard to if the original batch.path having a ?CFID... GET string. My simple solution was:
if (batch.path.match(/\?/)) {
batch.req.open("GET", batch.path + "&" + query);
} else {
batch.req.open("GET", batch.path + "?" + query);
}
... in the DWREngine._sendData()

Just some more info - CFAJAX has worked very well for us in all respects in the live production environment!
Posted by num on January 31, 2007 at 1:07 PM

Post a comment (login required)