javascript - .uploadifySettings not working as expected - Stack Overflow

I'm using uploadify and the function to change the settings doesn't seem to be working.I'

I'm using uploadify and the function to change the settings doesn't seem to be working.

I'm basing my code from the following example:

#(‘#someID’).uploadifySettings(’scriptData’, {‘name’ : some.val()});

So here's what I'm doing:

// INITIALIZATION
$("#"+elementId).uploadify({ 
  // other data
  "scriptData": {
     "token": token
  }
});

Later on I want to update the scriptData:

$("#"+elementId).uploadifySettings("scriptData",{"token": "pleasework"});

... but this is not working, it's still using the scriptData set during the initialization.

What am I doing wrong?


UPDATE: I need to do this because I need to handle tokens. Here's the worflow:

1- Get a token
2- Init uploadify with this token
3- Upload a file
4- Get another token asynchronously
5- Add the token to the already initialized uploadify (bugged)
6- Go to 3

I tried doing this on initialization:

"scriptData": {
   "token": $(".token").val()
}

... and update .token on step 4

This doesn't work either

UPDATE 2: Also if I do:

"scriptData": {
   "token": getAToken()
}

with

function getAToken(){
  alert("abcd");
  return "sometoken";
}

... I can see that the function getAToken only gets called once (only 1 alert)

I'm using uploadify and the function to change the settings doesn't seem to be working.

I'm basing my code from the following example:

#(‘#someID’).uploadifySettings(’scriptData’, {‘name’ : some.val()});

So here's what I'm doing:

// INITIALIZATION
$("#"+elementId).uploadify({ 
  // other data
  "scriptData": {
     "token": token
  }
});

Later on I want to update the scriptData:

$("#"+elementId).uploadifySettings("scriptData",{"token": "pleasework"});

... but this is not working, it's still using the scriptData set during the initialization.

What am I doing wrong?


UPDATE: I need to do this because I need to handle tokens. Here's the worflow:

1- Get a token
2- Init uploadify with this token
3- Upload a file
4- Get another token asynchronously
5- Add the token to the already initialized uploadify (bugged)
6- Go to 3

I tried doing this on initialization:

"scriptData": {
   "token": $(".token").val()
}

... and update .token on step 4

This doesn't work either

UPDATE 2: Also if I do:

"scriptData": {
   "token": getAToken()
}

with

function getAToken(){
  alert("abcd");
  return "sometoken";
}

... I can see that the function getAToken only gets called once (only 1 alert)

Share Improve this question edited Jun 14, 2010 at 15:37 marcgg asked Jun 7, 2010 at 12:41 marcggmarcgg 66.6k53 gold badges183 silver badges236 bronze badges 14
  • Do you have a demo page to show us? It might be a problem with another part of your script. – nebkat Commented Jun 10, 2010 at 9:54
  • @neb: No I'm sorry. It's on the admin section of an unannounced project :\ – marcgg Commented Jun 10, 2010 at 10:10
  • @neb: but aside from this issue, the rest of the script works perfectly – marcgg Commented Jun 10, 2010 at 10:10
  • @marcgg Im not sure on this then but best thing to do is get firebug for firefox(or google chrome inspector) to track your results step by step. Start off with a simple "uploadifySettings" change and keep goin until you find the problem. – nebkat Commented Jun 10, 2010 at 11:34
  • @neb I tried this and didn't find anything, that's why I ended up posting this question ^^ – marcgg Commented Jun 10, 2010 at 13:37
 |  Show 9 more ments

4 Answers 4

Reset to default 2

This works for me, adding a unique nonce to every file upload

            function setScriptData(){
                $("#product_attachment").uploadifySettings("scriptData", 
                    {
                      '_fsg_distro_session' : '<%= u cookies["_fsg_distro_session"] %>',
                      'authenticity_token'  : '<%= u form_authenticity_token if protect_against_forgery? %>',
                      'nonce'                               : new Date().getTime() + "<%= @current_user.id %>"                    
                    }
                );
                console.debug($("#product_attachment").uploadifySettings("scriptData"));
            }

            $("#product_attachment").uploadify({
                uploader                    : '/uploadify/uploadify.swf',
                script              : '/products/temp_upload',
                cancelImg           : '/uploadify/cancel.png',
                fileDataName        : 'asset[temp_file]',
                'queueID'           : 'fileQueue',
                onComplete              : function(event, ID, fileObj, response, data){ fileOnCompleteHandler(event,data); },
                onSelect                    : setScriptData,
                auto                : true,
                multi               : false,
                buttonImg           : '/images/attach.png',
                fileNameMaxLength   : 30
            });

I am using the latest Uploadify (2.1.0) and JQuery (1.4.1)

I've looked at the source and I notice that uploadifySettings() has an optional, undocumented (it does not appear here) third parameter. Apparently if you set it to true as in $("#"+elementId).uploadifySettings("scriptData",{"token": "pleasework"}, true); it will clobber the existing settings for scriptData and perhaps that will have some impact.

But based on the source I can't exactly tell what impact a change in settings necessarily has.

    uploadifySettings:function(settingName, settingValue, resetObject) {
        var returnValue = false;
        jQuery(this).each(function() {
            if (settingName == 'scriptData' && settingValue != null) {
                if (resetObject) {
                    var scriptData = settingValue;
                } else {
                    var scriptData = jQuery.extend(settings.scriptData, settingValue);
                }
                var scriptDataString = '';
                for (var name in scriptData) {
                    scriptDataString += '&' + name + '=' + escape(scriptData[name]);
                }
                settingValue = scriptDataString.substr(1);
            }
            returnValue = document.getElementById(jQuery(this).attr('id') + 'Uploader').updateSettings(settingName, settingValue);
        });

That code is from version 2.1.0.

Is there a way to potentially decide on the settings before initialization?

Also, I found this existing SO question: Uploadify updateSettings problems.

Try defining the function in-line at initialization? IE:

"scriptData": {
   "token": function() { return $("#token").val(); }
}

I'm not sure why this would be different than some of your other solutions though.

FOUND THE SOLUTION:

I had a mistake in the "onSelect" function. I had misspelled the element id name, instead file_upload I had fileUpload and thats why it didnt update the scriptData parameter. I know its a silly mistake but easy to be made. Here is the whole onSelect function:

'onSelect' : function(event,data) {
            $("#file_upload").uploadifySettings('scriptData', {'id' : $('#name_of_the_element').val()}
            );
        }

So check if this is the problem

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745216393a4617044.html

相关推荐

  • javascript - .uploadifySettings not working as expected - Stack Overflow

    I'm using uploadify and the function to change the settings doesn't seem to be working.I'

    7小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信