featur

[javascript] jquery formData() ajax upload 본문

개발/Javascript

[javascript] jquery formData() ajax upload

featur 2015. 11. 5. 11:43

 

 

[javascript] jquery formData() ajax upload

 

 

 

열마디 말보다 샘플이 이해하기 쉽겠죠


<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ajax formData test</title>
    <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>

</head>
<body>

    <form id="frm" method="post" enctype="multipart/form-data">
        <input type="file" name="review_image" />
        <input type="button" id="uploadbutton" value="클릭" />    </form>

    <div id="result"></div>

</body>
</html>


<script>

    $(function () {
        $("#uploadbutton").click(function () {
            var form = $('form')[0];
            var formData = new FormData(form);
            $.ajax({
                url: '/uplaod',
                processData: false,
                contentType: 'multipart/form-data',
                data: formData,
                type: 'POST',
                success: function (result) {
                    $("#result").html(result);
                }
            });
        });
    })
</script>

 

 


Comments