SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post Serialize upload

    Hi, can i ask some help why is that i could not get post value when using the jquery ajax and with the use of serialize data when uploading image file.
    i only get the value of input tpe="text" but the input type="file" i could not post the value.can someone help me on this please why it will not be posted.


    Thank you in advance.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jemz View Post
    Hi, can i ask some help why is that i could not get post value when using the jquery ajax and with the use of serialize data when uploading image file.
    i only get the value of input tpe="text" but the input type="file" i could not post the value.can someone help me on this please why it will not be posted.
    I didn't think that file uploads could be done via AJAX - can they?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Ahh - it seems that it's now possible - here's some details about how it can be done.
    http://stackoverflow.com/questions/1...758614#8758614

    And here's a jQuery plugin that helps you to easily do an ajax file upload
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi paul_wilkins, Thank you for this...so it must have plugins in order to get work with this file upload...

    Thank you i will try this one.

  5. #5
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    6,064
    Mentioned
    219 Post(s)
    Tagged
    12 Thread(s)
    Hi jemz,

    So I got and read your PM.
    I understand you don't want to make your code public and I will try and help you.

    The first thing you need to do is to make a small demo page that I can look at that demonstrates your issue.

    Then reply to this thread detailing what is not working. Say what you expect/would like to happen and what is actually happening.
    You can then PM me the address of the demo page that you have made.

    Once again, apart from that, please reply only in this thread.

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi pullo, My problem is that i have a form with input type="text" and it has input type="file" the problem is that i could not get the file when i am going to submit the form,because i am using the jquery.ajax to send. my form goes something like this.

    HTML Code:
    <form id="myform" action="tootherpage.php" enctype="multipart/form-data">
       <input type="text" name="fname">
       <input type="text" name="mname">
       <input type="text" name="lname">
     
      <input type="file" name="dataupload">
    
    </form>

    I tried to use .submit but nothing happens. is there other ways not to use pluguins?


    Thank you.

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Ahh - it seems that it's now possible - here's some details about how it can be done.
    http://stackoverflow.com/questions/1...758614#8758614

    And here's a jQuery plugin that helps you to easily do an ajax file upload
    Hi paul_wilkins,I am confuse what should i put in the "fileElemntId" is it the id of my form "myform"?

    HTML Code:
    <form id="myform"  enctype="multipart/form-data">
       <input type="text" name="fname">
       <input type="text" name="mname">
       <input type="text" name="lname">
     
      <input type="file" name="dataupload">
    
    </form>

    Code:
     $.ajaxFileUpload
            (
                {
                    url:'doajaxfileupload.php',
                    secureuri:false,
                    fileElementId:'fileToUpload',
                    dataType: 'json',
                    success: function (data, status)
                    {
                        if(typeof(data.error) != 'undefined')
                        {
                            if(data.error != '')
                            {
                                alert(data.error);
                            }else
                            {
                                alert(data.msg);
                            }
                        }
                    },
                    error: function (data, status, e)
                    {
                        alert(e);
                    }
                }
            )
           
            return false;
    
        }

    Thank you.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jemz View Post
    I am confuse what should i put in the "fileElemntId" is it the id of my form "myform"?
    Give the filename field a unique identifier and use that identifier also in the fileElementId section.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Give the filename field a unique identifier and use that identifier also in the fileElementId section.
    Hi, you mean like this

    HTML Code:
    <form id="myform"  enctype="multipart/form-data">
       <input type="text" name="fname">
       <input type="text" name="mname">
       <input type="text" name="lname">
     
      <input type="file" name="dataupload" id="myupload">
      <input type="submit" id="submit_btn" name="submit" value="submit">
    </form>
    and this is the script to send data

    Code:
    $('#submit_btn').click(function(){
       var ser_form = $('#myform').serialize();
        $.ajax({
           type: 'post',
           data: ser_form,
           url: 'process_toother.php'
           success: function(data){
          }
    
     });
    
    });
    
    
    
       $.ajaxFileUpload
            (
                {
                    url:'process_toother.php',
                    secureuri:false,
                    fileElementId:'myupload',
                    dataType: 'json',
                    success: function (data, status)
                    {
                        if(typeof(data.error) != 'undefined')
                        {
                            if(data.error != '')
                            {
                                alert(data.error);
                            }else
                            {
                                alert(data.msg);
                            }
                        }
                    },
                    error: function (data, status, e)
                    {
                        alert(e);
                    }
                }
            )
           
            return false;
    
        }
    is this correct ?please correct me if i am wrong.

    Thank you

  10. #10
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi @Pullo @paulwilkins, I fixed it now thank you for your help


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
  •