tags:

views:

53

answers:

2

All,

I am trying to perform a nested AJAX call using the following code. The nested call doesn't seem to work. Am I doing anything wrong?

$.ajax({
type: 'GET',
url: "/public/customcontroller/dosomething",
cache: false,
dataType: "html",
success: function(html_input)
{
    $.ajax({
        type: 'GET',
        url: "/public/customcontroller/getjobstatus",
        cache: false,
        dataType: "html",
        success: function(html_input){
        alert(html_input);
        }
    });                                                                       
}
});

Thanks

+1  A: 

You could be having thread-type issues, given that the outside call is asynchronous and may go out of scope before the success handler can come into play. Try breaking the success call out into a separate function.

Dave Swersky
+1  A: 

Try this

$.ajax({
type: 'GET',
url: "/public/customcontroller/dosomething",
cache: false,
dataType: "html",
async: false,
success: function(html_input)
{
    $.ajax({
        type: 'GET',
        url: "/public/customcontroller/getjobstatus",
        cache: false,
        dataType: "html",
        success: function(html_input){
        alert(html_input);
        }
    });                                                                       
}
});
Ben