【问题标题】:Passing current data with ajaxform使用 ajaxform 传递当前数据
【发布时间】: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


    【解决方案1】:

    您需要删除输入提交,而是放置一个按钮。 单击按钮时,您将信息存储在隐藏的输入标签中。 然后(使用jquery或其他方式)提交表单,然后您将通过html表单获取您在Php页面上设置的参数。

    编辑: 也就是说,在提交表单之前,每次打开文件夹时都会重新启动 g.storeFolder。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 2011-10-24
      • 1970-01-01
      • 2020-06-05
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多