jejacks0n/mercury — Issue #134: jquery scripts not being executed when injected through ajax
Author: shreyas-satish
Created: 2012-01-17 10:04:36+00:00
State: open

I'm trying to extend Mercury with a custom button/behavior.

The behavior is

imageUpload: function(selection) {
$.ajax({
dataType: 'script',
type: 'get',
url: '/admin/assets/image_upload'
});
}

When I click the custom button, the request response is

Started GET "/admin/assets/image_upload?_=1326791811171" for 127.0.0.1 at 2012-01-17 14:46:51 +0530
Processing by Admin::AssetsController#image_upload as JS
Parameters: {"_"=>"1326791811171"}
Rendered admin/assets/image_upload.js.erb (0.5ms)
Completed 200 OK in 63ms (Views: 61.7ms | ActiveRecord: 0.0ms)

My image_upload.js.erb is

alert("ss");
$('#mercury_iframe').contents().find("#custom-mercury-modal").show();

The alert window appears but the second line does not execute. When I execute the second line in the browser console, the div appears, as expected.
I'm using Rails 3.1.3 & Mercury 0.2.3