Uploading an image using AJAX and iframes

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Uploading an image using AJAX and iframes

Richard Durr-2
Hello List,

I am currently implementing an ImageChooser Component, where I like users to upload an image by submtiting the form containing the fileUpload using an iframe like this:


html form id: (self formId);  attributeAt: #target put: (self frameName); multipart; method: #post; with: [
html fileUpload
id: self uploadInputId;
accept: 'png jpg jpeg gif';
on: #image of: self.
html div with: [
html anchor
onClick: (html javascript factory form id: self formId; submit);
with: 'Upload Image'.
].
].
html iframe name: self frameName; style: 'display: none; widht: 0; height: 0; border: 0;'.

This works – but it loads the entire page into the iframe, again. I would rather just load an html stub containing a javascript which indicates if the upload was successful or not and executes in the context of the original html. I tried to return a response during the setting of my component's image instance-variable but this does not work.

Has anybody an Idea?

RD

_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Uploading an image using AJAX and iframes

Lukas Renggli
> This works – but it loads the entire page into the iframe, again. I would
> rather just load an html stub containing a javascript which indicates if the
> upload was successful or not and executes in the context of the original
> html. I tried to return a response during the setting of my component's
> image instance-variable but this does not work.
> Has anybody an Idea?

You need to start a new render loop (to avoid that the parent page is
displayed within the frame) and display some component. Try to add the
following code at the end of the method #image:

  ...
  WARenderLoop new
      show: (WAComponent new
           addMessage: 'File successfully uploaded';
           yourself)
      withToolFrame: false

Replace the expression within brackets with your own component that
displays the confirmation.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Uploading an image using AJAX and iframes

Richard Durr-2
Works great, thank you!
I have to learn so much more, there is still so much that I haven't fully groked, sigh. ^^

RD

On Fri, Aug 21, 2009 at 9:57 PM, Lukas Renggli <[hidden email]> wrote:
> This works – but it loads the entire page into the iframe, again. I would
> rather just load an html stub containing a javascript which indicates if the
> upload was successful or not and executes in the context of the original
> html. I tried to return a response during the setting of my component's
> image instance-variable but this does not work.
> Has anybody an Idea?

You need to start a new render loop (to avoid that the parent page is
displayed within the frame) and display some component. Try to add the
following code at the end of the method #image:

 ...
 WARenderLoop new
     show: (WAComponent new
          addMessage: 'File successfully uploaded';
          yourself)
     withToolFrame: false

Replace the expression within brackets with your own component that
displays the confirmation.

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside


_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside