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, therefo开发者_Python百科re 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;
});
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')
精彩评论