2010-02-19 31 views

回答

0

發送SimpleXMLElement::asXML()

自足的例子返回值:

<?php 
if (isset($_GET['foo'])) { 
    $foo = new SimpleXMLElement('<foo />'); 
    $foo->bar->baz[] = date('Y-m-d H:i:s'); 
    $foo->bar->baz[] = rand(1,100)." la la la"; 
    header('Content-type: application/xml; charset=utf-8'); 
    echo $foo->asXML(); 
    die; 
} 
?><html> 
    <head> 
    <title>...</title> 
    <script type="text/javascript" src="jquery/jquery-1.3.2.min.js"></script> 
    <script type="text/javascript"> 
     function foo() { 
     $.ajax({ 
      type: "GET", 
      url: "?", 
      data: { "foo":1 }, 
      dataType: "xml", 
      success: function(xml) { 
      $(xml).find("baz").each(function(){ 
       $("#div1").append($(this)); 
       $("#div1").append("<br />"); 
      }) 
      }, 
      error: function() { 
      alert("that didn't work"); 
      } 
     }); 
     } 
    </script> 
    </head> 
    <body> 
    <button onclick="foo()">click</button> 
    <div id="div1">...</div> 
    </body> 
</html>