gpt4 book ai didi

javascript - .uploadifySettings 未按预期工作

转载 作者:搜寻专家 更新时间:2023-11-01 04:27:53 25 4
gpt4 key购买 nike

我正在使用 uploadify并且更改设置的功能似乎不起作用。

我的代码基于以下示例:

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

所以这就是我正在做的:

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

稍后我想更新脚本数据:

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

...但这不起作用,它仍在使用初始化期间设置的 scriptData。

我做错了什么?


更新:我需要这样做是因为我需要处理 token 。这是工作流程:

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

我尝试在初始化时这样做:

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

...并在第 4 步更新 .token

这也行不通

更新 2:另外,如果我这样做:

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

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

...我可以看到函数 getAToken 只被调用一次(只有 1 个警报)

最佳答案

这对我有用,为每个文件上传添加一个唯一的随机数

            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
});

我正在使用最新的 Uploadify (2.1.0) 和 JQuery (1.4.1)

关于javascript - .uploadifySettings 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2989533/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com