在 JavaScript 会话中存储表单数据
-
20-09-2019 - |
题
我想知道是否可以在 JavaScript 会话中存储“标题”和“描述”等表单数据?
我正在使用 uploadify 脚本来创建 Flash 上传器,但该脚本未传递标题和说明。这是我目前的代码;
<script type="text/javascript">
jQuery(document).ready(function() {
title = $("input#title").val();
description = $("textarea#description").val();
$('#uploadImage').uploadify({
'uploader': 'flash/uploadify.swf',
'script': 'process/process_uploaded_image.php',
'folder': 'submitted/pictures',
'cancelImg': 'images/cancel.png',
'queueID' : 'fileQueueImages',
'auto' : false,
'multi' : false,
'fileExt' : '*.jpg;*.png;*.gif;*.jpeg;*.JPG',
'fileDesc': 'Images ONLY (.jpg, .png, .gif, .jpeg, .JPG)',
'buttonText' : 'BROWSE',
'scriptData': {'title':title,'description':description,'user':'<?php echo $usr["id"] ?>'},
'sizeLimit' : '2097152', //2MB
//'buttonImg' : '/components/com_mm/assets/images/button-upload-images.png',
//'width' : '218',
//'height' : '66',
onAllComplete: function() {
//$('#uploadedImage').load(location.href+" #uploadedImages>*","");
//location.reload(); //uncomment this line if youw ant to refresh the whole page instead of just the #allfiles div
location.href = "upload-pics-thanks.php";
},
//onComplete: function(a, b, c, d, e){
// if (d !== '1')
// alert(d);
//},
onError: function (a, b, c, d) {
alert("Error: "+d.type+" Info: "+d.info);
},
onSelect: function () {
}
});
});
</script>
解决方案
看看这个 所以答案 如果这不起作用......
您在 Uploadify 论坛中看到这篇文章了吗?也许它会为您指明正确的方向,并且哇这些论坛中有这么多垃圾邮件。
其他提示
JavaScript 没有会话。也许最好的方法是通过 AJAX 将标题和描述发送到服务器。
如果您使用最新版本的uploadify,数据在 scriptData
将被传递到 script
作为任一 _POST
或者 _GET
(默认是现在 POST
) 多变的。因此,在您的 php 文件中,您可以使用以下命令获取标题和描述:
$_POST['title']
$_POST['description']
$_POST['user']
只需将其视为与处理表单提交相同,只是它源自 uploadify flash。另请注意,Flash 不会传递浏览器中当前存在的当前 cookie。如果您的 php 使用存储在 cookie 中的会话,则必须对其进行调整以从 $_POST
反而。
我使用 CodeIgniter,CodeIgniter 论坛中有相应的补丁。如果你只是在 PHP 会话中使用 build,你可以通过 PHPSESSID
里面 scriptData
, ,然后在侧面 script
PHP,使用传递的数据重新初始化会话。stackoverflow 中的其他问题已经回答了,只需使用 uploadify 关键字搜索即可。
不隶属于 StackOverflow