0

html img returned from ajax has class of 'tocrop'. Currently I Calling the function on the success of the ajax call:

$("#imageform").ajaxForm({
        target: '#image_upload_preview',
        success: jcropp(),
})

function jcropp(){
    $('.tocrop').Jcrop();
    }

I have tried using .load(), setInterval() and clearInterval(when $('.tocrop').Jcrop()), .bind() to bind a function after it has loaded...nothing seems to work

There has already been a thread on this but the solutions did not work

Any help would be greatly appreciated This is being returned from server, have already tried binding $('.tocrop').load()to jcrop function:

<img class='tocrop' src='/tempupload/".$upload_data['file_name']."'/>
Community
  • 1
  • 1
A_funs
  • 1,228
  • 2
  • 19
  • 31

1 Answers1

1

do you want

success: jcropp

instead of

success: jcropp()  

like

$("#imageform").ajaxForm({
    target: '#image_upload_preview',
    success: jcropp
});

or something like, if you want to check image load event also in success. Please clarify what you are returning from server, if its some html then you should bind a load event for image as the image might not be loaded at the time success is triggered.

$("#imageform").ajaxForm({
    target: '#image_upload_preview',
    success: function(data){
        jcropp();
        }
});

from your comment "html retuned from server has class toload"

$("#imageform").ajaxForm({
    target: '#image_upload_preview',
    success: function(data){
        var src = $('.tocrop').attr('src');
        $('.tocrop').load(function(){
            $(this).Jcrop();
            }).attr('src',src);
        }
});
sabithpocker
  • 15,274
  • 1
  • 42
  • 75
  • I already tried using .load() but why are you messing with the src attribute here? – A_funs Jun 25 '12 at 20:59
  • ok this worked thanks, I think I didn't wrap the second function. But i omitted the .attr() stuff, don't know what you were trying to do there – A_funs Jun 25 '12 at 21:04
  • setting src after defining load() makes suree its fired, also it looks like, when success is called the element may not yet be inseted into DOM, can you just try alert($('.tocrop').length && $('.tocrop').attr('src')) inside success to make sure it exists at that time – sabithpocker Jun 25 '12 at 21:04