如何使此Javascript与特定的操作表单一起工作?

如何使此Javascript与特定的操作表单一起工作?,javascript,forms,action,Javascript,Forms,Action,我目前正在为上传视频脚本制作一个上传进度条。 因此,当我的表单块中有action=“[var.path\u to\u upload\u script]”时,我的视频上传工作正常 因此,让我首先粘贴我正在处理的所有代码 以下是表格代码: <div> <form name="form_upload" id="form_upload" method="post" enctype="multipart/form-data" action

我目前正在为上传视频脚本制作一个上传进度条。 因此,当我的表单块中有
action=“[var.path\u to\u upload\u 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" />&nbsp;&nbsp;&nbsp;<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();">&nbsp;&nbsp;&nbsp;<input type="button" id="submit" name="submit" value="Upload" onClick="uploadFiles();">');
            //-->
            </script>
        </div>
以及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>

$(文档).ready(函数(){
//
setInterval(函数()
{
$.get(“?progress_key=&randval=“+Math.random(),{
//获取对当前URL(upload\u frame.php)的请求,该URL调用页面顶部的代码。它根据文件id“progress\u key=”检查文件的进度,并使用以下函数返回值:
},
函数(数据)//从jQuery的get请求返回信息
{
$(“#进度_容器”).fadeIn(100);//淡入进度条
$(“#进度条”).width(数据+“%”;//根据$status值设置进度条的宽度(设置在此页面顶部)
$('#progress_completed').html(parseInt(data)+“%”;//在进度栏中显示完成的百分比
}
)},500);//间隔设置为500毫秒(进度条将每.5秒刷新一次)
});
现在,如果我从表单块中的操作中删除
[var.path\u to\u upload\u script]
,则进度条工作正常,但文件上载脚本失败

因此,我想问一下如何使进度条在表单标记中使用
action=“[var.path\u to\u upload\u script]”


提前谢谢

您正在使用php代码设置属性,但它看起来像是某种模板:

$('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');

同样的问题也可能出现在这里:
谢谢@Ilya Bursov,但它不是这样工作的。现在它没有显示加载的百分比。当我从表单中的操作中删除
[var.path\u to\u upload\u script]
并使其看起来像
action=“”
@tonlystruck check更新的答案时,进度条开始工作,看起来您有2个问题。我得到的id像
,它工作正常。为什么我必须更改它?@tonlystruck检查我的答案,我告诉你更改模板,而不是后台服务器代码我如何才能使
[var.path\u to\u upload\u script]
中发布数据,并使用
action=“”
$('#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]');