如何使这个Javascript与特定的操作形式一起工作
How to make this Javascript work with a specific action form?
我目前正在处理一个上传视频脚本的上传进度条。因此,当我的表单块中有action="[var.path_to_upload_script]"
时,我的视频上传运行良好。
因此,让我首先粘贴我正在处理的所有代码。
这是表单代码:
<div>
<form name="form_upload" id="form_upload" method="post" enctype="multipart/form-data" action="[var.path_to_upload_script]" style="margin: 0px; padding: 0px;">
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
<noscript><input type="hidden" name="no_script" value="1" /></noscript>
<input type="hidden" name="title" value="[var.title]" />
<input type="hidden" name="description" value="[var.description]" />
<input type="hidden" name="tags" value="[var.tags]" />
<input type="hidden" name="location_recorded" value="[var.location_recorded]" />
<input type="hidden" name="allow_comments" value="[var.allow_comments]" />
<input type="hidden" name="allow_embedding" value="[var.allow_embedding]" />
<input type="hidden" name="public_private" value="[var.public_private]" />
<input type="hidden" name="channel" value="[var.channel]" />
<input type="hidden" name="channel_name" value="[var.channel_name]" />
<input type="hidden" name="sub_cat" value="[var.sub_cat]" />
<input type="hidden" name="form_submitted" value="yes" />
<div id="upload_slots"><span class="font5_16"><b>[var.lang_please_upload]</b></span><input type="file" name="upfile_0" size="71" value="" /></div>
<br />
<iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
<br />
<noscript><br><input type="reset" name="no_script_reset" value="Reset" /> <input type="submit" name="no_script_submit" value="Upload" /></noscript>
</form>
<script language="javascript" type="text/javascript">
<!--
document.writeln('<input type="button" name="reset_button" value="Reset" onClick="resetForm();"> <input type="button" id="submit" name="submit" value="Upload" onClick="uploadFiles();">');
//-->
</script>
</div>
这里重要的是在表单action="[var.path_to_upload_script]"
块中具有操作,否则文件的上传将不起作用。
这是进度条JAVASCRIPT代码:
$('#upload_frame').show();
function set () {
$('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
}
setTimeout(set);
还有来自upload_frame.php的代码
<?php
$url = basename($_SERVER['SCRIPT_FILENAME']);
//Get file upload progress information.
if(isset($_GET['progress_key'])) {
$status = apc_fetch('upload_'.$_GET['progress_key']);
echo $status['current']/$status['total']*100;
die;
}
//
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
<link href="style_progress.css" rel="stylesheet" type="text/css" />
<script>
$(document).ready(function() {
//
setInterval(function()
{
$.get("<?php echo $url; ?>?progress_key=<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), {
//get request to the current URL (upload_frame.php) which calls the code at the top of the page. It checks the file's progress based on the file id "progress_key=" and returns the value with the function below:
},
function(data) //return information back from jQuery's get request
{
$('#progress_container').fadeIn(100); //fade in progress bar
$('#progress_bar').width(data +"%"); //set width of progress bar based on the $status value (set at the top of this page)
$('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
}
)},500); //Interval is set at 500 milliseconds (the progress bar will refresh every .5 seconds)
});
</script>
<body style="margin:0px">
<!--Progress bar divs-->
<div id="progress_container">
<div id="progress_bar">
<div id="progress_completed"></div>
</div>
</div>
<!---->
</body>
现在,如果我从表单块中的操作中删除[var.path_to_upload_script]
,进度条正常工作,但文件上传脚本失败。
所以我想问一下如何使进度条与表单标签中的action="[var.path_to_upload_script]"
一起使用?
提前感谢!
您正在使用PHP代码设置属性,但看起来它是某种模板:
$('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
尝试更改为
$('#upload_frame').attr('src','upload_frame.php?up_id=[var.up_id]');
同样的问题可能在这里:<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
相关文章:
- 如何使jQuery插件函数可调用以供独立使用,而不在集合上操作
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- 转义符不能与innerHTML一起使用
- 如何确定javascript已经完成了某些操作.ios上的
- 防止Alt+Shift默认操作或检测多种操作系统语言的Javascript
- 从JavaScript访问struts操作中的属性
- fluxxor向一个flux实例添加一组以上的操作
- Jquery表单验证插件-如果选中复选框,如何在提交时执行某些操作
- 高亮显示与数组字符串一起使用时文本插件中断
- 操作放置在画布上的元素之间的连接
- 使用“+="操作人员
- Rails操作只调用一次,但我在ajax中每秒钟都调用一次
- Jquery未定义函数正在停止其他操作
- 如何操作iframe之外的元素
- setTimeout可以与闭包内的函数一起使用吗
- 将依赖外部库的UMD模块与browserfy捆绑在一起
- Highcharts colorsByPoint与系列中的线性渐变一起使用时不起作用
- 如何使这个Javascript与特定的操作形式一起工作
- error: destroy.js. erbb没有与destroy操作一起运行
- 为什么操作(在 MVC 4 中 ASP.NET)不与 onclick 事件一起运行