You are here:
JQuery - The write less, do more javascript library JQuery - The write less, do more javascript library

Problem passing + parameter to jQuery Uploadify

I have battled with a problem today using jQuery uploadify on a project I am currently working on. For some reason my string parameter was being stripped of the '+' characters. Here was my code:

$(document).ready(function() {
$('#.asset-upload').uploadify({
... 'scriptData': {
domainKey = 'M++ddfkjkjer7374834jnjdfnjsdfDfg5565' ...
}
});
});

When this code gets executed my backend script was receiving the data for "domainKey" but without the "+" characters. It was very strange and only seemed to occur with the "+" character. After some intense googling I stumbled across a solution over at Stack Overflow. This solution was for a problem with a Rails App that was having the same difficulty (Passing params from swfupload/uploadify to Rails app - broken?)

The solution was to use encodeURIComponent() inside your javascript function, before sending the data to the backend processign script. A code snippet:

$(document).ready(function() {
$('#asset-upload').uploadify({
... 'scriptData': {
domainKey = encodeURIComponent(encodeURIComponent('M++ddfkjkjer7374834jnjdfnjsdfDfg5565')) ... }
});
});

Thanks to acidburn2k for the answer.