如何“生活”我的jquery(表单插件)上传例程,如下所述?
第一次点击按预期上传和刷新列表,但是用户无法上传第二个文件,因为它似乎没有触发javascript,我已经尝试了几个“.live('submit'”组合与此插件但是避风港没解决:
JQuery使用表单插件:
$(document).ready(function() {
var options = {target: '#uploads_panel',
data:
{ upload_ajax_on:'1',
upload:'1'
}
};
$('#upload-form').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
表格如下:
<div id='uploads_panel'> <!-- for ajax refresh -->
//table containing existing file list
<form action="/file/upload" method="post" id="upload-form" enctype="multipart/form-data">
<p>File<br />
<input type="file" name="userfile" id="userfile" /></p>
<p><input type="submit" value="Submit" /></p>
</form>
</div>
,控制器如下所示:
public function uploadAction()
{
//fetch variables etc
if(isset($_POST['upload']))
{
$data=array();
$data[name] = $_FILES['userfile']['name'];
$data[internal_name] = date("Y-m-d-h-m-s",time()).$data[name];
$data[type] = $_FILES['userfile']['type'];
$data[size] = $_FILES['userfile']['size'];
$data[path] = 'uploads/'. $_SESSION['customer_id'] . "/".$data[internal_name];
$data[upload_time] = time();
$data[user_id] = $_SESSION['user_id'];
$data[customer_id] = $_SESSION['customer_id'];
$tmpName = $_FILES['userfile']['tmp_name'];
$testervar=$uploadDir.$data[internal_name];
$result = move_uploaded_file($tmpName, $uploadDir.$data[internal_name]);
if (!$result)
{
echo "Error uploading file";
die;
}
$db = new DBitems();
// $last_id=$db->uploadFile($data);
}
$upload_ajax_on=$_POST['upload_ajax_on'];
$dbitems = new DBitems();
$filelist=$dbitems->selectFilesByCustomerId($_SESSION['customer_id']);
$this->registry->template->filelist =$filelist;
if(isset($upload_ajax_on))
{
$this->registry->template->setView('masterpage','layouts:ajax');
$this->registry->template->setView('contents','customers:table_upload');
}
else
{
$returnurl=$_POST['returnurl'];
$this->registry->router->redirect($returnurl);
}
}
答案 0 :(得分:1)
您是否尝试过在uploads_panel div之外移动表单?不确定是否受到更新的影响?希望有帮助吗?