You don't need an iframe for that.

Something similar to this (not tested) should be enough

<input id="fileinput" type="file" name="file" onchange="uploadIt()">

<script>
function uploadIt() {

        var xhr = new XMLHttpRequest();

        xhr.upload.addEventListener('progress',function(ev){
                var progress = (ev.loaded/ev.total)*100;
                console.log('Upload progress: '+progress+"%");
        }, false);

        xhr.onreadystatechange = function(ev) {
          if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                        if(xhr.responseText != 'error')
                        {
                                console.log('Upload done');
                        }
                } else {  
                  console.log("Upload Error "+ xhr.statusText);  
                }  
          }
        };

        xhr.open('POST', "xhr_upload.php", true);
        var files = document.getElementById('fileinput').files;
        var data = new FormData();
        data.append('file', files[0]);
        xhr.send(data);
}
</script>


Remi


Le 28 août 2013 à 01:40, KR <[email protected]> a écrit :

> I just managed to get it working.   I just implemented the same hidden iframe 
> approach that I used on desktop.
> 
> Instead of submitting the form with a submit button, I did a button calling 
> <form>.submit()  to make sure it did a normal submit and not an IUI ajax 
> submit.
> 
> The form had target=<hidden iframe>
> 
> It turns out that my response is either an alert if an error or a redirect 
> anyway, so I was able to code a responds_to_parent  block which sends some JS 
> to the parent of the iframe.    So, in the end, it works just like desktop 
> bypassing IUI completely.
> 
> Thanks for your input on this problem.
> Kurt    
> 
> 
> 
> On Tuesday, August 27, 2013 2:10:17 PM UTC-7, Sean Gilligan wrote:
> Responses inline... 
> 
> 
> On 8/27/13 11:44 AM, KR wrote: 
> > I actually run my desktop app on iPad's and am adding this support 
> > there, but it's a normal submit and working fine. 
> > 
> > I have found that the OS's that don't support HTML5 file fields render 
> > the file field as disabled and then don't return the parameter in the 
> > response, so I downgrade automatically to my existing approach where 
> > they can email the file. 
> 
> I'm assuming the file is a photo?  Is that correct? 
> 
> 
> > Sean - my IUI version is old and modified so I'm not sure we'll get a 
> > useful patch from this work. 
> 
> If you get a chance try doing a diff between the unmodified copy of the 
> version of iUI you are using and the latest version.  Look at the 
> changes in form handling and see if you can merge in just those 
> changes.  It has been significantly improved and that may help you with 
> adding file upload. 
> 
> 
> One other question: are you using jQuery or Zepto? 
> 
> -- Sean 
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "iPhoneWebDev" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/iphonewebdev.
> For more options, visit https://groups.google.com/groups/opt_out.

-- 
You received this message because you are subscribed to the Google Groups 
"iPhoneWebDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/iphonewebdev.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to