views:

42

answers:

1

I'm using the jquery form plugin (http://malsup.com/jquery/form/) to upload a file via ajax which is processed in the background.

The upload is working correctly, and I am using ASP.Net MVC to return a partial view which contains a $(document).ready call to setup a 'timer' to check on the status of the upload file's processing status. When I return the partial view which contains a script block wit ha $(document).ready call, it is never fired, therefore the 'timer' to check for the status of the upload is never started.

When I do this via a regular $.post call (without upload) the function fires correctly after the html is loaded into the DOM. Is there anything else I need to do when calling the ajaxSubmit function to get this to fire?

Just a sample bit of code:

$('form').live('submit', function () {
                $(this).ajaxSubmit({                   
                    success: function (data) {                        
                        $('#statusDiv').html(data);                        
                    }
                });               
                return false;
            });
+1  A: 

Can your ASP.Net MVC partial view loading routine fire off a callback routine? You could try watching for a custom event bound using .live() in your main document's ready() handler. Then .trigger('custom_event') in your partial view callback. Something like:

$(document).ready( function(){
    $('container_for_partial_view').live('custom_event', function(){
        set_timer_and_do_stuff()
    }
})

...and when the partial view is loaded via ajax:

$('container_for_partial_view etc etc').trigger('custom_event')
Ken Redler
This ended up working, although I was hoping for a 'cleaner' solution. I had to pull a value from the html returned in the partial view using a hidden field, but it worked.I think I was trying to add more 'logic'(javascript) into the partial view, but that should probably all be done in the container page that was originally loaded.
ncyankee