【发布时间】:2014-11-12 16:18:00
【问题描述】:
我有一个用来上传图片的表单:
<form action="uploadImage.php" method="post" enctype="multipart/form-data" id="UploadForm">
<input type="file" id="fileInput" name="ImageFile" help_token="upload_token" size=20 />
<input type="submit" id="SubmitButton" help_token="upload_token" value="Upload" />
<img id="loadGif" src="images/ajax-loader.gif" alt="load gif" />
</form>
我用 ajaxform 准备表单:
var statustxt = $('#statustxt');
var submitbutton = $("#SubmitButton");
var myform = $("#UploadForm");
var galleryStatus2$ = $("#galleryStatus2");
var error_code;
$(myform).ajaxForm({ // called when the code loads
data : {dstDir : g.currentGal}, // pass in some $_POST parameters
resetForm : true,
beforeSend: function() { //before submitting the form
galleryStatus2$.empty(); // clear status from last upload
submitbutton.attr('disabled', ''); // disable upload button
$('img#loadGif').fadeIn(200); // start spinner
},
complete: function(response) { // upload complete
console.log("<br />upload complete. g.currentGal = " + g.currentGal);
galleryStatus2$.html(response.responseText); //upload status
submitbutton.removeAttr('disabled'); //enable submit button again
$('img#loadGif').fadeOut(200); // kill spinner
我遇到的问题是我希望能够告诉动作脚本uploadImage.php,上传到哪个目录。我尝试使用“数据:{dstDir:g.gurrentGal}”行来做到这一点。 g.currentGal 保存最后一个双击的文件夹,即最后一个打开的文件夹,因此现在是任何上传的目标。但是 ajaxform 代码在最初加载代码时运行,而不是在提交表单时运行。所以 g.currentGal 是 JavaScript 首次加载时变量初始化的值,而不是最后一个文件夹打开时的值。如何在提交表单时获取 g.currrentGal 的值以传递给 $_POST 数组中的 uploadImage.php?
谢谢
【问题讨论】:
标签: javascript php jquery forms ajaxform