开发者

show jquery dialog

开发者 https://www.devze.com 2023-02-19 17:12 出处:网络
Xml <?xml version=\"1.0\" encoding=\"utf-8\"?> <Questions> <Question> <Id>1</Id>

Xml

<?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>

Code1

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 () {                                                  
                }
        }); 
    });

This code Get XML successes.

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

Code2

function PopupUserRegist() {        
     $.ajax({   
     type: "GET",
     url: "../Administrator/Questions.xml",
     success: parseXmlQuestion
     });
    function parseX开发者_开发技巧mlQuestion(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 () {                                                  
                }
        }); 
    });
}

This code does not Get XML successes.

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

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

in Code1: autoOpen: false and in code2: autoOpen: true

in code1 get xml success but in code2: does not get xml.


When the dialog is autoOpened, it may be before the XML has been fully loaded and parsed. I would call the dialog at the end of parseXmlQuestion() so that the timing is correct for all parts of your script.

If you need a loading indicator while the user waits, use something like this:

$('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();
});
0

精彩评论

暂无评论...
验证码 换一张
取 消