使用uploadify将其他发布数据发送到服务器时出现问题 [英] Problem sending additional post data to server with uploadify

查看:44
本文介绍了使用uploadify将其他发布数据发送到服务器时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个页面上使用uploadify,该页面允许用户上传图像以及在其中发送这些图像的类别字段.现在,我看到uploadify提供了"scriptData"方法,该方法使我可以将键值对发送到uploadify.php脚本.但是问题在于scriptData方法在页面加载(uploadify初始化)时获取其值.因此,当用户在页面上更改值时,scriptData仍仅具有页面加载时存在的默认值.

I'm using uploadify on a page that allows a user to upload images as well as a category field in which to send those images. Now, I see that uploadify provides a "scriptData" method that allows me to send over key value pairs to the uploadify.php script. But the problem is that the scriptData method grabs its values upon page load(uploadify initialization). Thus when a user is on the page changing values, scriptData still only has the default values that were there on page load.

这附近还有吗?

感谢一百万!

可能的解决方案:我正在进一步阅读手册,发现可以通过函数调用来更改设置.可能在正确的轨道上?

Possible solution: I was reading the manual further and discovered that you can change the settings through a function call. Possibly on the right track?

$('#fileInput').uploadifySettings('scriptData', getKeyValuePairs()).uploadifyUpload();

现在正在处理..

推荐答案

,您需要通过uploadify的回调函数之一onOpen或onSelect来获取用户输入的当前状态.请参阅其文档以获取正确的文档.我猜onOpen会更可靠,因为它将在每次上载开始时检查用户输入的当前状态.尽管如此,您可能仍需要在上载进行时禁用其他用户输入,或者仍然需要用户提交表单,否则最后一次上载开始后所做的任何用户输入都将丢失.

you would need to fetch the current state of the user's input via one of uploadify's callback hoock: onOpen or onSelect . See their documentation for the right one. I guess onOpen is more reliable as it will check the current state of user input everytime an upload is started. Still, you might need to disable other user inputs while an upload is ongoing, or still require the user to submit the form, otherwise any user input done after the last upload has started will be lost.

无论如何,我在他们的论坛上找到了这个,我将其放在onOpen回调中:

Anyway, I found this on their forum, which i would put on a onOpen callback:

$('#fileInput2').uploadifySettings(
'scriptData', 
{'ext':$('#dirTimeStamp').val(), 'ext2':$('#txtEmail').val()}
);

最终的实现是(使用演示代码):

A final implementation would be (using the demo code) :

<input id="fileInput" name="fileInput" type="file" />
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$('#fileInput').uploadify({
'uploader'  : 'uploadify.swf',
'script'    : 'uploadify.php',
'cancelImg' : 'cancel.png',
'auto'      : true,
'folder'    : '/uploads',
'onOpen' : function(){
$('#fileInput').uploadifySettings(
    'scriptData', 
    {'ext':$('#dirTimeStamp').val(), 'ext2':$('#txtEmail').val()}
    );
}
});
});
// ]]></script>

这篇关于使用uploadify将其他发布数据发送到服务器时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆