2011-03-26 5 views
0

XML을쇼 JQuery와 대화

<?xml version="1.0" encoding="utf-8"?> 
<Questions> 
    <Question> 
    <Id>1</Id> 
    <Text>aaaa</Text>  
</Question> 
<Question> 
    <Id>2</Id> 
    <Text>bbb</Text>  
</Question> 
</Questions> 

HTML

<table dir="rtl" width="400px"> 
      <tr> 
       <td> 
        <span id="signuptitle">ques* : </span> 
       </td> 
       <td> 
        <select id="sctQuestion" name="D2"> 
         <option></option> 
        </select> 
       </td> 
      </tr> 

코드 1

function PopupUserRegist() {   
    $.ajax({ 
    type: "GET", 
    url: "../Administrator/Questions.xml", 
    success: parseXmlQuestion 
    }); 

    function parseXmlQuestion(xml) 
    { 
     $(xml).find("Question").each(function() 
     { 
      var value=$(this).find('Text').text();  
      $("#sctQuestion"). 
      append($("<option></option>"). 
      attr("value",value). 
      text(value)); 
    }); 
    } 
$("#div_userregist").dialog("open"); 
} 

    $(function() { 

     $("#dialog:ui-dialog").dialog("destroy"); 
     $("#div_userregist").dialog({ autoOpen: false, 
      buttons: { 
       "ok!": function() {             
       } 
     }); 
    }); 

이 코드 가져 오기 XML 성공.

============================================== ============================

CODE2

function PopupUserRegist() {   
    $.ajax({ 
    type: "GET", 
    url: "../Administrator/Questions.xml", 
    success: parseXmlQuestion 
    }); 
    function parseXmlQuestion(xml) 
    { 
     $(xml).find("Question").each(function() 
     { 
      var value=$(this).find('Text').text(); 
      $("#sctQuestion"). 
      append($("<option></option>"). 
      attr("value",value). 
      text(value)); 
     }); 
    }  
    $(function() { 

     $("#dialog:ui-dialog").dialog("destroy"); 
     $("#div_userregist").dialog({ autoOpen: true, 
      buttons: { 
       "ok!": function() {             
       } 
     }); 
    }); 
} 

이 코드는 XML의 성공을하지 않습니다.

============================================== ===================

=========================== ======================================

코드 1에

:에 AutoOpen : 허위의 CODE2는 :에 AutoOpen : 코드 1의 진정한

는 XML 성공하지만 CODE2에서 얻을 : XML을하지 않습니다.

답변

0

대화 상자가 자동으로 열리면 XML이 완전히로드되고 구문 분석되기 전에있을 수 있습니다. parseXmlQuestion() 끝의 대화 상자를 호출하여 스크립트의 모든 부분에 타이밍이 맞도록하십시오.

사용자가 기다리는 동안 로딩 표시가 필요한 경우,이 같은 것을 사용

$('body').append('<div id="ajaxBusy"><p><img src="images/loading.gif"></p></div>'); 

// Ajax activity indicator bound to ajax start/stop document events 
$(document).ajaxStart(function(){ 
    $('#ajaxBusy').show(); 
}).ajaxStop(function(){ 
    $('#ajaxBusy').hide(); 
});