srs81 / CakePHP-AjaxMultiUpload

CakePHP 2 plugin to allow for easy multi-file upload with AJAX
Other
65 stars 33 forks source link

AMU Form inside Ajax response javascript not enabled #21

Closed michka closed 12 years ago

michka commented 12 years ago

Hi,

I put a AMU Edit Form inside a ajax response with jquery. The problem is there is no Upload button displayed, so I can't upload files.

Inside the AjaxMultiUploadPost___x Div, there is only the Noscript tag that invite me to enable Javascipt to use File Uploader. If I use the Edit action directly without Ajax, then all is working perfectly.

Is someone know a solution of this situation ?

Thank you.

srs81 commented 12 years ago

Interesting. When you say "Ajax response", are you loading up the button through an iframe? Or is it on the page already, and just not displayed until you make the Ajax call?

michka commented 12 years ago

Thank you for your response.

I don't know a lot about iframe. So I'm not an expert but I will try to explain shortly what I do :

I made a $('#link').click(function.... where there is a $.ajax inside it. This Ajax call a basic Cakaphp 'edit.ctp' with '$this->Upload->edit.....' inside it. On Ajax success I update a Div with $ '#dynEditForm').html(data) and just after that I call a Javascript function. This function made a lot of things like Jquery animations (dynamic apparition of the edit form) and Ajax evaluations.

So I never see an Iframe in the code of my website and if I go directly to the form with myWebSite/posts/edit/1, all it's ok and there no Iframe to in the code.

michka commented 12 years ago

I found the solution. I think the problem was with Javascript inside Ajax response. The createUploader function in UploadHelper don't run with "window.onload = createUploader; " (line 89 of createUploader). So I put a createUploader call in the success part of my Ajax call. I can see now the upload button running.

srs81 commented 12 years ago

Nice. Yeah, Javascript callbacks from AJAX page loads is a tough one to debug, particularly when the Javascript is being called from within the page that is being loaded and depends on a window or body load.