如何在joomla模块中通过javascript发送输入文件类型 [英] how to send a input file type via javascript in joomla modules

查看:68
本文介绍了如何在joomla模块中通过javascript发送输入文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用javascript发送一个文件到php文件。

我在我的php文件中有这个表单

I want to send a file with javascript to php file .
I have this form in my php file

<form action="" method="post" enctype="multipart/form-data">
   <label for="file">Filename:</label>
   <input type="file" name="file" id="file1"><br>
   <p id="poi">upload</p>
   <p id="plo"></p>
</form>

并在js文件中将此代码设为白色

and white this code in js file

jQuery(document).on("click","#poi",function(){
   var objfile=new FormData();
   var file=jQuery("#file1").get(0).files[0];
   objfile.append("iefile078",file);

   var ajax ;
   ajax.upload.addEventListener("progress" ,progresshandler ,false);
   function progresshandler(){
      jQuery("#plo").text("uploading ....");
   }
   ajax.open("POST","helper.php");
   ajax.send(objfile);
});

当我点击我页面上的上传时,此功能正常启动。

我想在上传进行上传....时向用户显示。

另外我想将此文件发送到helper.php文件。

如何设置属性为open()和send()函数在这种情况下传递上传到helper.php的文件?

这是我的文件结构,我的表单位于default.php

when I click on the "upload" on my page this function fired correctly.
I want to when upload is progressing "uploading .... " show to user.
additionally I want to send this file to helper.php file.
how to set attribute to the open() and send() function in this case to passing file uploaded to the helper.php?
this is my file structure and my form place in the default.php

js
    jquery.js
tmpl
    default.php
helper.php
mod_upload.php
mod_upload.xml


推荐答案

尝试这个:

$(document).on("click","#poi", function(e) {
    e.preventDefault();
    var formData = new FormData($(this)[0]);

    $.ajax({
        url: 'helper.php',
        type: 'POST',
        data: formData,
        async: false,
        beforeSend: function() {
            $("#message1").show().html("uploading...");
        },
        success: function(data) {
            $("#message1").fadeOut();
            $("#container").html(data);
        },
        cache: false,
        contentType: false,
        processData: false
    });
});

这篇关于如何在joomla模块中通过javascript发送输入文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆