Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

upload file using ajax

// add jquery
// <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
$(document).ready(function() {
  $("#form").on('submit', (function(e) {
    e.preventDefault();
    $.ajax({
      url: $(this).attr('action'),
      type: "POST",
      data: new FormData(this),
      contentType: false,
      cache: false,
      processData: false,
      success: function(response) {
        $("#form").trigger("reset"); // to reset form input fields
      },
      error: function(e) {
        console.log(e);
      }
    });
  }));
});
Comment

ajax file upload input

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>File Uploads With AJAX</title>
</head>
<body>
    <form id="file-form" action="fileUpload.php" method="post" enctype="multipart/form-data">
        Upload a File:
        <input type="file" id="myfile" name="myfile">
        <input type="submit" id="submit" name="submit" value="Upload File Now" >
    </form>

    <p id="status"></p>
    <script type="text/javascript" src="fileUpload.js"></script>
</body>
</html>

Code language: HTML, XML (xml)
Comment

ajax file upload

$(function() {
    // Configure Cloudinary
    // with the credentials on
    // your Cloudinary dashboard
    $.cloudinary.config({ cloud_name: 'YOUR_CLOUD_NAME', api_key: 'YOUR_API_KEY'});
    // Upload button
    var uploadButton = $('#submit');
    // Upload-button event
    uploadButton.on('click', function(e){
        // Initiate upload
        cloudinary.openUploadWidget({ cloud_name: 'YOUR_CLOUD_NAME', upload_preset: 'YOUR_UPLOAD_PRESET', tags: ['cgal']}, 
        function(error, result) { 
            if(error) console.log(error);
            // If NO error, log image data to console
            var id = result[0].public_id;
            console.log(processImage(id));
        });
    });
})
function processImage(id) {
    var options = {
        client_hints: true,
    };
    return '<img src="'+ $.cloudinary.url(id, options) +'" style="width: 100%; height: auto"/>';
}
Code language: JavaScript (javascript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: remove the bottom selection line from materail ui 
Javascript :: auto refresh vue pwa 
Javascript :: Minimum Path Sum for loop 
Javascript :: angular routing appcomponent snipped 
Javascript :: mobile version 
Javascript :: javascript object duplicate keys 
Javascript :: javascript change favicon dynamicly 
Javascript :: linux Error HH604: Error running JSON-RPC server 
Javascript :: how to create session cookie in node js 
Javascript :: js function call itself 
Javascript :: $Javascript $.get( 
Javascript :: express.js routing 
Javascript :: access data from dofferent file in js 
Javascript :: delete file firebase angular 
Javascript :: Maxscript Bitarray 
Javascript :: @typescript-eslint/no-empty-function 
Javascript :: angular date passed to donet care is a day less 
Javascript :: get time in between two dates javascript dayjs 
Javascript :: Plumsail To change the modal popup window size you can try injecting the CSS to the SharePoint list view page 
Javascript :: react-folder tree example 
Javascript :: folder array randomizer 
Javascript :: javascript axios response.data.pipe not a function 
Javascript :: Why is the return function in my debounce function never called? Angularjs 
Javascript :: How to set up path paramater in angular and access in the controller 
Javascript :: Angular js set default tab with ng-repeat in array object 
Javascript :: sfc setup vue 3 mounted method - lifecycle methods in sfc 
Javascript :: get lat long from address google api 
Javascript :: image react not showing 
Javascript :: javascript encriment +1 
Javascript :: set of these properties: in js 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =