开发者

How to process/eval $ajax response as html/javascript when loading into a jquery dialog in MVC 3?

I have index page with a list of users and an edit link. When I click this link I wold like to open a jquery dialog to edit a开发者_开发技巧nd then save.

I am doing an ajax get on another view and loading the return data into a div. The return data is html and javascript both. The return is just text essentially. I need the javascript in the return to be executed, sort of like running eval. Is this possible or is there a better way to do it? I guess I could just open it in a window.open or an iframe. However I was wondering if jquery dialog or any other model dialog solution is possible? Is there a recommended way?

   $.ajax({
                type: "GET",
            url:  "/User/Edit/" + user.Id,
            cache: false,
            dataType: 'html',
            error: function (xmlHttpRequest) {                  
                $("#edit-dialog").html(xmlHttpRequest.responseText);
            },
            success: function (data) {
                $("#edit-dialog").html(data);                   
                $("#edit-dialog").dialog("open");
            }             
        });

The page edit is more than just a simple form - it has reasonable amount of javascript and ui candy. Thanks!


Inline JavaScript should be executed as soon as the browser renders it. I think the problem is you are using document.ready to initialize, but this will never fire if you add the HTML after initial page rendering. 2nd, all JavaScript has to come after HTML, because JS will not find HTML elements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜