My 5th book "50 Tips on JavaScript" is on sale. Go get it from
Illustrated guide to 50 of the most interesting JavaScript topics.

A strange IOErrorEvent.IO_ERROR event dispatched

Really simple GET request from a flex based application. However it fails if GET parameters are passed.

var obj:Object = {property: "value"};
var urlString:String = "" + JSON.encode(obj);
var urlRequest:URLRequest = new URLRequest(urlString);
urlRequest.method = URLRequestMethod.GET;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, complete);
urlLoader.addEventListener(ProgressEvent.PROGRESS, progress);
urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
urlLoader.addEventListener(IOErrorEvent.IO_ERROR, IOError);

In the above example *IOError* is called. I firstly checked for *crossdomain.xml* on the server, because sometimes that cause such problems. Unfortunately there was crossdomain policy file, so the problem was somewhere else. I removed *JSON.encode(obj)* from the url and everything was ok. The problem was that the passed json encoded string wasn't urlencoded. Here is the fix:

var urlString:String = "" + escape(JSON.encode(obj));
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. To leave a comment go here.