首页 > 解决方案 > 我应该将“单击”更改为“绑定”吗?它不能一起工作

问题描述

早上好,我有这两个 javascript 代码,但我无法让它们都工作。当两者都嵌入到我的页面中时,负责将文档上传到文件夹的代码停止工作。我在任何地方都看不到错误,我在哪里失败了?提前致谢。

$(function() {

  // grab the file input and bind a change event onto it
    $('#file').bind("change", function() {
    // new html5 formdata object.
$('#botondecarga').hide();
$('#cargando').show();

        var formData = new FormData();
formData.append('carpeta', $('#carpeta[name="carpeta"]').val());
        //for each entry, add to formdata to later access via $_FILES["file" + i]
        for (var i = 0, len = document.getElementById('file').files.length; i < len; i++) {
            formData.append("file" + i, document.getElementById('file').files[i]);
        }


        //send formdata to server-side
        $.ajax({
            url: "file-upload.php", // our php file
            type: 'post',
            data: formData,
            dataType: 'html', // we return html from our php file
            async: true,
            processData: false,  // tell jQuery not to process the data
            contentType: false,
              // tell jQuery not to set contentType
            success : function(data) {
              confirm("Documentos subidos satisfactoriamente.");
                          location.reload();

            },
            error : function(request) {
                console.log(request.responseText);
            }
        });
    });
});

$(document).ready(function(){
  

    var maxField = 10; //Input fields increment limitation
    var addButton = $('.add_button'); //Add button selector
    var wrapper = $('.field_wrapper'); //Input field wrapper
    var fieldHTML = '<div id="cantidadstock" class="cantidadstock"></div><div class="form-group"><label>Producto</label><select class="form-control select2" name="producto[]" id="producto" required><?php
        $clase_newstock->lista_productos_almacen_principal_formulario();
    ?></select><label>Cantidad</label><input type="number" name="cantidad[]" class="form-control" value=""/><div class="form-group"><label>Fecha recepcion</label><div class="input-group"><div class="input-group-addon"><i class="fa fa-calendar"></i></div><input type="text" id="fecha_recepcion" name="fecha_recepcion[]" class="form-control"></div><div class="form-group"><label for="nombre">N albaran proveedor</label><input type="text" class="form-control" id="albaran_proveedor" name="albaran_proveedor[]" placeholder="El numero de albaran del proveedor..."></div><div class="form-group"><label for="precio">Precio</label><input type="number" class="form-control" id="precio" name="precio[]" placeholder="Precio...(Solo números y punto para decimales) "></div><br><a href="javascript:void(0);" class="remove_button btn btn-warning">Quitar producto</a></div>'; //New input field html
    var x = 1; //Initial field counter is 1

    //Once add button is clicked
    $(addButton).click(function(){
        //Check maximum number of input fields
        if(x < maxField){
            x++; //Increment field counter
            $(wrapper).append(fieldHTML); //Add field html
            $('.select2').select2();
        }
    });

    //Once remove button is clicked
    $(wrapper).on('click', '.remove_button', function(e){
        e.preventDefault();
        $(this).parent('div').remove(); //Remove field html
        x--; //Decrement field counter
    });
});

标签: javascriptphp

解决方案


推荐阅读