InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

jQuery tutorials

    jQuery Ajax

    • jQuery JSONP
    • jQuery .post()
    • jQuery .load()
    • load script with cache enabled
    • jQuery .ajax() file upload

    jQuery CSS

    • change table cells color based on value
    • check if element is visible in viewport
    • display auto fade out message
    • fitvids.js for automatically resizing videos
    • get class list of an element
    • jQuery toggleClass() examples
    • make a div stick at top on scroll
    • table with alternate color rows

    jQuery Events

    • Javascript/jQuery - disable right click
    • jQuery - text input field - change keyup and paste events
    • trigger click using jQuery or Javascript

    jQuery DOM

    • jQuery html() vs text()
    • Check if an element exists
    • find total DOM elements
    • jQuery encode string to html entities
    • jQuery - read and modify iframe content
    • jQuery - create iframe with content
    • jQuery - find select element selectedIndex, value and text
    • jQuery - get checkbox value and checked state
    • jQuery - get javascript object

    jQuery Cookbook

    • get jQuery version
    • jQuery - add text to existing div
    • jQuery sliding effect - slideUp, slideDown, slideToggle

    jQuery UI

    • jQuery UI make element movable
    • jQuery ui slider and input text box - one way binding
    • jQuery ui slider and input text box - two way binding
     
    • Home
    • > Tutorials
    • > Javascript
    • > jQuery

    jquery ajax – post form having file uploads

    on Feb 15, 2016

    To post a form using jQuery Ajax, we can directly call jQuery .ajax() methods passing form data. The form data can be constructed using FormData. Note that here jQuery serialize() won’t work due to the presence of file uploads. Also note that FormData does not work in IE.

    Here is code snippet which uses jQuery Ajax to submit a form. Just select any file and click submit to see the Ajax response.

    <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
    <form id="form1" action="/api/post-dump.php" method=POST>
    name1: <input type="text" name="name1" value="value1" /><br/>
    file1: <input type="file" name="file1" value="value2" />
    <input type="submit" name="submit" value="submit"/>
    </form><br/>
    Response from server:
    <pre id="result" style="background-color:lightgray;"></pre>
    
    <script type="text/javascript">
    $("#form1").submit(function() {
      var action = $("#form1").attr("action");
      data = new FormData($("#form1")[0]);
      $.ajax({
        url: action,
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        type: 'POST',
        success: function(data){
          $("#result").html(data);
        }
      });
      return false;
    });
    </script>
    refresh done
    try it online

    Suggested posts:

    1. ReactJS – convert jsx to javascript using babel cli
    2. Requirejs – quickstart guide for beginners
    3. jQuery encode string to html entities
    4. CSS attribute presence and value selectors
    5. CSS general sibling selector
    6. Mac – how to always show scroll bar
    7. Jquery – change table cells color based on value
    8. React basic clock example using setInterval
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged HTML, jQuery, jQuery Ajax, Web Development
    • Browse content
    • Article Topics
    • Article archives
    • Contact Us
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

    Copyright © 2025 InfoHeap.

    Powered by WordPress