SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jun 2013
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to upload file using jquery ajax() method?

    Here i tried using below codes but it didn't save file name in database but other text fields are saved.so my doubt is how to store file using jquery ajax() method.

    Code JavaScript:
    $(document).ready(function(){
    $("#category").click(function(){
    var filename = $("#file").val();
    $.ajax({
    type: "POST",
    url: "save.php",
    data:$("#form-cover").serializeArray(),
    success: function() {
    alert("Inserted");
    }
    });
    return false;
    });
    });

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    You should probably use a FormData object to accomplish this; Mozilla have a demonstration page here
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,151
    Mentioned
    16 Post(s)
    Tagged
    3 Thread(s)
    The easiest and most cross-browser friendly method is to use an iframe as proxy.

    Searching the query below in Google should yield some examples of implementations.

    "using iframe to upload file with ajax"
    The only code I hate more than my own is everyone else's.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •