开发者

Problem with loading inline javascript in a PartialView

开发者 https://www.devze.com 2022-12-16 03:41 出处:网络
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 Vi

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();
    });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消