My Projects
Search Blog

Categories
Archives
Useful Links
Photo Albums
RSS

Powered by
BlogCFM v1.15

Vivio Technologies Dedicated Hosting
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 | 5 comments
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

Re: Getting CFAJAX to handle Safari properly
Hi There,
There is still a problem with the convertDataPassedToCFFunctionParam fix. I am using cfajax 1.3
Here is the problem- the fix that you have is on CF side- bu that is a bit too late... because, in my case of setup, when the length of the string passed through GET method is too long, the browser kills the request (HTTP 414 URI too long error) BEFORE the request ever leaves the client side browser! So the server side fix does not help anything.

You mention above "Safari browsers were force to use the GET method..." I see that is still the case in CFAJAX 1.3 (look at engine.js and search for safari- there is an if case that is forcing afari to use GET).

Any idea what to do?
Posted by vahe on May 24, 2010 at 9:13 AM

Re: Getting CFAJAX to handle Safari properly
My suggestion - stop using CFAJAX. It's loaded with security issues.
Posted by rickroot on May 24, 2010 at 10:06 AM

Re: Getting CFAJAX to handle Safari properly
Any replacement suggestions? It's worked fine for the most part, except this glitch on Safari browsers.
But if you know of a more robust interface for talking between ajax and CF, I'd love to know about it!
Posted by vahe on May 24, 2010 at 10:15 AM

Re: Getting CFAJAX to handle Safari properly
that's the thing.. you don't NEED anything like cfajax for coldfusion to speak ajax. All you need is to be able to serialize data into JSON. So if you're using CF8 or better, you just use a .cfm that puts the result into a variable then call #serializeJSON(variable)# ... the variable can be a string, struct, array, whatever.

If you're using CF7, you do have to write your own serializer. Or use the one on CFLIB:

http://www.cflib.org/udf/jsonencode

You can also, with coldfusion 8 or higher, just set the returnFormat=JSON" and call the CFC directly via ajax... ie...

http://mydomain.com/myobject.cfc?method=myMethod¶m1=foo

BUT, if you really feel you must use something like cfajax, you could go with AjaxCFC by Rob Gonda (http://www.robgonda.com/blog/projects/ajaxcfc/) but really, such things are totally unnecessary now.
Posted by rickroot on May 24, 2010 at 11:03 AM

Post a comment (login required)