M
M
msimrial2015-11-12 15:08:36
PHP
msimrial, 2015-11-12 15:08:36

Upload files from ajax?

<form method="post"  enctype="multipart/form-data" id="file-form">
                <div class="form-group">
                    <label for="dfile">Загрузить файл можно только XLSX Бдьте уверены в этом!</label>
                    <input type="file" name="dfile" id="dfile" class="form-control">
                </div>
                <div class="form-group">
                        <!--<input  name="submit" type="submit" value="Send" class="btn btn-success" id="upload-button">-->
                        <button type="submit" id="upload-button">Upload</button>
                </div>
            </form>
            <h4 id='loading' >loading..</h4>
            <div id="message"></div>
<script>
    $(document).ready(function (e){
        $('#upload-button').click(function (e){
            e.preventDefault();
            $("#message").empty();
            $('#loading').show();
        });
        $.ajax({
            url: 'UpdateCitymarket.php',
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            success: function(data)   // A function to be called if request succeeds
            {
                $('#loading').hide();
                console.log(data);
                $("#message").html(data);
            }
        })
    })
</script>

if(isset($_FILES["dfile"]["type"])){
echo "hello";
}


I'm trying to upload a file via ajax but nothing happens, can you tell me a good tutorial

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kostryukov, 2015-11-12
@msimrial

your click is closed..

});
        $.ajax({

like this:
$(document).ready(function (e){
        $('#upload-button').click(function (e){
            e.preventDefault();
            $("#message").empty();
            $('#loading').show();
       // });
        $.ajax({
            url: 'UpdateCitymarket.php',
            type: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            success: function(data)   // A function to be called if request succeeds
            {
                $('#loading').hide();
                console.log(data);
                $("#message").html(data);
            }
        });
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question