views:

67

answers:

1

Hi all, I have nested ajax calls that are not working in ie7. They work fine in Firefox. The service file in the second $.post is not being entered at all. In other words, if the first line of my service file is print 'hello'; I never see it...even if I add a console.log in the $.post for the response. I have seen this issue in other places too... http://www.mail-archive.com/[email protected]/msg34270.html

/**
* Listener for saving page content to the database and an associative flat file
* 
* @return void
*/
$(document).ready(function()
{
    // Listen for the save button click
    $('#save-button').live('click', function()
    {
        // Disable the save button just in case of repeat submits
        $('#save-button').attr('disabled', 'disabled');

        // Loop through the micro template children
        $('#micro-template').children().each(function()
        {
            var id = $(this).attr('id');

            // Remove random content from the DOM for this node
            $(this).find('.random-content').remove();

            // Remove divs that don't matter (contains edit buttons)
            $(this).find('.' + id).remove();

            // Remove unwanted area (contains edit buttons)
            $(this).find('.remove').remove();

            // Remove firebug div
            $(this).find('#_firebugConsole').remove();

            // Remove the class definition for the current item
            $(this).removeAttr('class');

            // Loop through the children's children
            $(this).children().each(function()
            {
                // Remove mouseover actions
                $(this).removeAttr('onmouseover');

                // Remove divs with no data
                if ($(this).html() == '')
                {
                    $(this).remove();
                }

                // Remove empty styles
                if ($(this).attr('style') == '')
                {
                    $(this).removeAttr('style');
                }
            });

            // Get the DOM HTML for this node
            var html = $(this).html();

            // Get the properties for the page
            $.post('../services/getsession.php', function(session)
            {
                // Setup the content result
                var obj = {
                    obj:        session,
                    data:       html,
                    microdiv:   id
                };

                // Insert the content result for the node into the databse
                $.post('../services/addContent.php', obj, function(response)
                {
                    // Check for errors
                    if (response != 'success')
                    {
                        var msg = '<p class="user-error"><b>Error</b><br />Failed to add your content. Reason: ' + response + '</p>';
                        $('#micro-template').append(msg);
                        var $err = $('#micro-template').find('.user-message');
                        if ($err.is(':visible'))
                        {
                            // Slides out a DOM element with the class 'user-message' after 2 seconds
                            $(this).delay(2000,function(){
                                $err.slideUp('slow');
                                self.close();
                            });
                        }
                        return false;
                    }
                    else
                    {
                        $(opener.document).find('#step-three-div').hide();
                        $(opener.document).find('#step-one-div').show();
                        $(opener.document).find('form').css('width', '70%');
                        $(opener.document).find('form').css('height', '460px');

                        var $err = $('#micro-template').find('.user-message');
                        if (!$err.is(':visible'))
                        {
                            var msg = '<p class="user-message"><b>Information</b><br />Successfully added your content</p>';
                            $('#micro-template').append(msg);
                            var $err = $('#micro-template').find('.user-message');
                            if ($err.is(':visible'))
                            {
                                // Slides out a DOM element with the class 'user-message' after 2 seconds
                                $(this).delay(2000,function(){
                                    $err.slideUp('slow');
                                    self.close();
                                });
                            }
                        }
                    }
                });
            });
        });
    });
});
+1  A: 

you are not passing second argument in your first ajax call. It should be

$.post('../services/getsession.php', {}, function(session){});

Also try putting second ajax call in a function and call that function once your first ajax completes.

$.post('../services/getsession.php', {}, function(session){    
            var obj = {
                obj:        session,
                data:       html,
                microdiv:   id
            };

            mysecondAjaxCall(obj);
});

If it doesnt solve the problem then put delay before calling function mysecondAjaxCall().

Ayaz Alavi