2010-08-18 8 views
2

ie7에서 작동하지 않는 중첩 된 ajax 호출이 있습니다. Firefox에서 잘 작동합니다. 두 번째 $ .post에있는 서비스 파일이 전혀 입력되지 않습니다. 즉, 내 서비스 파일의 첫 번째 행이 'hello'로 인쇄되면; 나는 그것을 보지 못했다. 응답의 $ .post에 console.log를 추가하더라도. 난 당신이 첫 번째 아약스 호출에서 두 번째 인수를 전달하지 않습니다 너무 다른 장소에서이 문제 ... http://www.mail-archive.com/[email protected]/msg34270.htmlIE7에서 중첩 된 ajax 호출이 작동하지 않습니다.

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

여기에 두 개의 글이 왜 있는지 잘 모르겠습니다. getsession.php의 기능을 addContent.php에서 호출 된 메소드로 옮길 수 있습니까? 필요한 모든 변수를 단일 게시물 요청에 전달한 다음 addContent.php를 실행하고 동일한 응답을 다시 가져올 수 있습니다. –

+0

헤이, 내 솔루션을 참조하십시오 나는 이런 종류의 문제도 발생했습니다. –

답변

0

을 보았다.

두 번째 ajax 호출을 함수에 넣고 첫 번째 Ajax가 완료되면 해당 함수를 호출 해보십시오.

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

      mysecondAjaxCall(obj); 
}); 

문제가 해결되지 않으면 함수 mysecondAjaxCall()을 호출하기 전에 지연을 넣으십시오.

관련 문제