ajax通过post方法向php进程发送日期值

我正在使用 php 和 ajax 上传带有进度条动画的多个文件 一切正常,除了我无法使用 Post 方法获取日期值此代码返回空变量


$expire = $_POST['expire'];

我试图改变读取$expirefrom值的顺序$_POST['expire'] 但我总是得到一个空值!


这是我的 import.php(包含上传多个文件的表单):


<input type="file" name="file[]" id="file" required multiple accept="application/pdf" />

<input type="date" name="expire" class="form-control" min="<?php echo date('Y-m-d') ?>" />

<button type="submit" id="submit" name="submit" class="btn btn-success" style="width:100%">

   Commencer <i class="fa fa-upload"></i>

</button>

并且它包含te ajax代码来调用upload.php进程



document.getElementById('submit').addEventListener('click', function(e){

    e.preventDefault();

    var f = document.getElementById('file'),

        pb = document.getElementById('progressbar'),

        pt = document.getElementById('progressbar-text'),

        btn = document.getElementById('submit');


    btn.innerHTML = "Chargement en cours …";

    btn.disabled = true;    


    app.uploader({

        files: f,

        progressBar: pb,

        progressText: pt,

        processor: 'upload.php',


        finished: function(data){

            //


        },


        error: function() {

            alert('Erreur ! veuillez réessayer SVP');

        }

    });



});


守着星空守着你
浏览 171回答 1
1回答

qq_遁去的一_1

干得好。我已经修改了您的代码,因此它包含 ID 为“过期”的输入值。您必须修改 HTML 代码,并且您的过期输入没有附加 ID。<input type="file" name="file[]" id="file" required multiple accept="application/pdf" /><input type="date" name="expire" id="expire" class="form-control" min="<?php echo date('Y-m-d') ?>" /><button type="submit" id="submit" name="submit" class="btn btn-success" style="width:100%">Commencer <i class="fa fa-upload"></i>上传.jsvar app = app || {};(function(o) {&nbsp; &nbsp; "use strict";&nbsp; &nbsp; // private methods&nbsp;&nbsp; &nbsp; var ajax, getFormData, setProgress;&nbsp; &nbsp; ajax = function(data) {&nbsp; &nbsp; &nbsp; &nbsp; var xmlhttp = new XMLHttpRequest(), uploaded;&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.addEventListener('readystatechange', function(){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(this.readyState === 4){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(this.status === 200){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uploaded = JSON.parse(this.response);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(typeof o.options.finished === 'function') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; o.options.finished(uploaded);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(typeof o.options.error === 'function') {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; o.options.error();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.addEventListener('progress', function(event) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var percent;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(event.lengthComputable === true){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; percent = Math.round((event.loaded / event.total) * 100);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setProgress(percent);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; });&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.open('post', o.options.processor);&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.send(data);&nbsp; &nbsp; }&nbsp; &nbsp; getFormData = function(source, expire) {&nbsp; &nbsp; &nbsp; &nbsp; var data = new FormData(), i;&nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i < source.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;data.append('file[]', source[i]);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; data.append('ajax', true);&nbsp; &nbsp; &nbsp; &nbsp; data.append('expire', expire);&nbsp; &nbsp; &nbsp; &nbsp; return data;&nbsp; &nbsp; };&nbsp; &nbsp; setProgress = function(value){&nbsp; &nbsp; &nbsp; &nbsp; if(o.options.progressBar !== undefined){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; o.options.progressBar.style.width = value ? value + '%' : 0;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; if(o.options.progressText !== undefined){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; o.options.progressText.innerText = value ? value + '%' : '';&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; };&nbsp; &nbsp; o.uploader = function(options) {&nbsp; &nbsp; &nbsp; &nbsp; o.options = options;&nbsp; &nbsp; &nbsp; &nbsp; if(o.options.files !== undefined){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ajax(getFormData(o.options.files.files, o.options.expire.value));&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; };}(app));阿贾克斯代码:document.getElementById('submit').addEventListener('click', function(e){&nbsp; &nbsp; e.preventDefault();&nbsp; &nbsp; var f = document.getElementById('file'),&nbsp; &nbsp; &nbsp; &nbsp; pb = document.getElementById('progressbar'),&nbsp; &nbsp; &nbsp; &nbsp; pt = document.getElementById('progressbar-text'),&nbsp; &nbsp; &nbsp; &nbsp; btn = document.getElementById('submit'),&nbsp; &nbsp; &nbsp; &nbsp; expire = document.getElementById('expire');&nbsp; &nbsp; btn.innerHTML = "Chargement en cours …";&nbsp; &nbsp; btn.disabled = true;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; app.uploader({&nbsp; &nbsp; &nbsp; &nbsp; files: f,&nbsp; &nbsp; &nbsp; &nbsp; progressBar: pb,&nbsp; &nbsp; &nbsp; &nbsp; progressText: pt,&nbsp; &nbsp; &nbsp; &nbsp; processor: 'upload.php',&nbsp; &nbsp; &nbsp; &nbsp; expire: expire,&nbsp; &nbsp; &nbsp; &nbsp; finished: function(data){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp; error: function() {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert('Erreur ! veuillez réessayer SVP');&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });});
打开App,查看更多内容
随时随地看视频慕课网APP