Problem with loading inline javascript in a PartialView
This question relates to my previous question which asks about loading a page into a DIV asynchronously using jquery/ajax. It has been resolved and it works like charm :). Now the problem is in the View that is asynchronously loaded to the DIV , I'm having a partial view. The partial view intern contains some javascript. When I load the page using ajax/jquery combination it does not load the javascript portion of the PartialView (i.e ascx). But if I load the page directly by typing the url , it shows the javascript pr开发者_如何学Pythonoperly! Does anybody know a explanation to this behavior?
thanks in advance
/BB
Javascript is not executed from content loaded by ajax an call. In order to make this work you will need to externalize javascript that needs to be executed into a separate function which you will invoke in the success callback.
$('#searchResults').load('/admin/users', {}, function() {
someFunctionThatNeedsToBeExecuted();
});
UPDATE:
To execute the function on dropdown change you could do the following:
$('#searchResults').load('/admin/users', {}, function() {
$('#someDropDownInsertedByThePartialView').change(function() {
someFunctionThatNeedsToBeExecuted();
});
});
精彩评论