Clicky

Hi,
This is the code I am using for picture upload using iframe, The below function is triggered once in IE, but with the second time, the load is not getting called.
$("#iframe").load(function(){
                        var iframeContents=$("#postframe").contents().find("body").html();
                        $("#uploaddiv").html(iframeContents);
                        $("#iframe").unbind('load');
                    });
Is there any way to overcome it?

asked 12/15/2011 03:04

gaurih's gravatar image

gaurih ♦♦


9 Answers:
have you tried commenting     $("#iframe").unbind('load');
link

answered

chaituu's gravatar image

chaituu

Hello,

When you load something it means that the script file that includes the functions can not take any action on the load element because it wasn't exist before in the DOM.
So after using the .load() you have to call again your script file with a getscript('path/filename/example.js');

Be carefull... do not use into getscript the file itself.

I mean, if the function you want to work after load() is at test1.js and you have also
in the same file the .load() function, you must take care of that you have to cut and paste the code to another js file and then this file will be the getscript() file that you have to call after the load. Otherwise you will put your code into a endless loop.

link

answered 2011-12-15 at 23:09:07

alex_code's gravatar image

alex_code

@chaituu:Yes I removed unbind and tested..

@alex_code: if that is the case, it should not even work for first time. the load is getting called and the contents are loaded in iframe. The issue is with second call.
link

answered 2011-12-16 at 01:30:52

gaurih's gravatar image

gaurih

I don't know exactly the structure of your code and if you call this load() only in a click function or even in document ready for the first time. If the first time that load() executes after document ready for example, the elements are in the DOM so that's the reason that works for the first time and not at the second. So please try what I suggest you on my previous post and then you will see.
link

answered 2011-12-16 at 08:41:53

alex_code's gravatar image

alex_code

This is the entire function that I am calling for upload, Can you please give me clue which part goes in getscript?

uploadImage: function () {
           $('#imageFile').live('change', function(){
            var iframe = $( '<iframe name="postframe" id="postframe" width=0 height=0 class="hideText" />' );
            $('div#iframe').append( iframe );
                     $('#buttonUpload').click();
           });
      $("#buttonUpload").live("click", function(e) {
        e.preventDefault();
        var userFile = $('#imageFile').val();
        $('#pictureUpload').attr( "action", "./imageUpload" );
        $('#pictureUpload').attr( "method", "post" );
        $('#pictureUpload').attr( "imageFile", userFile );
        $('#pictureUpload').attr( "enctype", "multipart/form-data" );
        $('#pictureUpload').attr( "target", "postframe" );
        $('#pictureUpload').submit();
       
     //need to get contents of the iframe
      $("#postframe").load(function(){
         var iframeContents=$("#postframe").contents().find("body").html();
         $("#pictureUploadComponent").html(iframeContents);
         $("#postframe").unbind('load');
        });
        return false;
       });
     
      },
link

answered 2011-12-16 at 08:52:15

gaurih's gravatar image

gaurih

@alex_code: Thank you for your solution. It works perfectly. Before closing this forum, I have other query in the same code:
 var iframeContents=$("#postframe").contents().find("body").html();
         $("#pictureUploadComponent").html(iframeContents);

iframecontents is returning null for the second time in IE. How to resolve it.
link

answered 2011-12-16 at 11:48:19

gaurih's gravatar image

gaurih

Small correction from the above query, it is returning value but image is not getting refreshed.
link

answered 2011-12-16 at 15:21:38

gaurih's gravatar image

gaurih

oops! noticed that getScript refreshes the page. it's not acting like ajax response
link

answered 2011-12-16 at 15:23:34

gaurih's gravatar image

gaurih

Glad to help you :-)
link

answered 2011-12-16 at 15:36:11

alex_code's gravatar image

alex_code

Your answer
[hide preview]

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Tags:

×63

Asked: 12/15/2011 03:04

Seen: 185 times

Last updated: 12/16/2011 07:43