locked
Convert jQuery code to angularjs RRS feed

  • Question

  • User1793652459 posted

    Hello,

    I am trying to use an example from this website for a file upload to a folder however they use jQuery and I am supposed to use angularjs only.

    http://www.encodedna.com/webapi/multiple-file-upload-using-html5-jquery-ajax-webapi.htm

    This is the HTML markup:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Multiple File Upload with HTML5, Ajax and Web API</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    </head>

    <body style="font:15px Verdana;">

    <form action="">
    Select Your Files:
    <input type="file" id="file" name="file" multiple />
    <input id="btUpload" type="button" value="Upload File"/>
    <p></p>
    </form>

    </body>

    This is the jQuery being used, can someone help me convert this to angular or guide me how to call this function in angularjs in a controller when a the upload button is clicked:

    <script>
    $(document).ready(function () {
    $("#btUpload").click(function () {

    var data = new FormData($('form')[0]);

    $.ajax({
    type: "POST",
    url: '/api/fileupload/', // CALL WEB API TO SAVE THE FILES.
    enctype: 'multipart/form-data',
    contentType: false,
    processData: false, // PREVENT AUTOMATIC DATA PROCESSING.
    cache: false,
    data: data, // DATA OR FILES IN THIS CONTEXT.
    success: function (data, textStatus, xhr) {
    $('p').text(data);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
    alert(textStatus + ': ' + errorThrown);
    }
    });
    });
    });
    </script>

    Thank you

    Monday, October 2, 2017 6:44 PM

Answers

All replies