Click here to Skip to main content
15,879,239 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Friends,

I am facing an issue in my current development in MVC Application, where i give an ajax call to load a partial view. That partial view returns a html in response. and further that html is been assigned to a childdiv.
JavaScript
$.ajax({
        type: "POST",
        url: $('#baseurl').val() + "sample url",
        data: jsonString,
        contentType: "application/json; charset=utf-8",
        dataType: "html",
        success: function (response) {
            $("#Middle").children().find("div#sampleDiv").html(response);
        },
        error: function () {
        },
        complete: function () {
        }
    });

Now problem is that "response" html is having a $(document).ready() state which does not execute in i assign $("#Middle").children().find("div#sampleDiv").html(response);.

my question is how to explicit call/execute document.ready of response html.
Posted
Updated 15-Jun-14 23:20pm
v2

1 solution

You have some problems with your approach...
1. No ready state when partial page load done...
2. The response content is inserted inside a div tag and never evaluated by the browser engine so browser knows nothing about any JavaScript method in that content, that will prevent you to call that peace of code even directly...
Basically the best approach is to break ajax callback into pieces...
One call to retrieve new content and an other to get JavaScript and execute it.
Look http://api.jquery.com/jquery.ajax/ for dataType: 'script'
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900