Search code examples
javascriptajaxjqueryjqmodal

How to assign an Ajax success handler when loading jqmodal dialog?


What I need is very simple but, searching the web, I didn't find any example.

I am using the jqModal jQuery plugin for displaying content dynamically (via Ajax) in a modal dialog. Once, this modal content is loaded, I need to bind some event on the dialog DOM elements. Therefore, I would like to assign an handler to the "success" AJAX event for manipulating these DOM elements.

The problem is that, looking into the jqModal documentation, there is no 'success' defined events. For instance, the code:

$('#ex2').jqm({ajax: 'examples/2.html', trigger: 'a.ex2trigger'});

will call the examples/2.html for the Ajax request and the response content will replace ex2 content...

...but how can I define my handler for success (or error) such that I can bind some events on the new content of '#ex2' ?

Thank you in advance for your help,

Fabien.


Solution

  • I'm guessing you're using the jqModel plugin? For success (not sure of error) you can add onLoad(callback) as detailed here

    So for instance

    $('#ex2').jqm({ajax: 'examples/2.html', trigger: 'a.ex2trigger', onLoad: doStuff});
    
    function doStuff() {
       //Do stuff here
    }