我在PHP文件中生成XML数据: -
private static function getAddressesAsXML($addressArr) {
$addressXML = new SimpleXMLElement("<addresslist></addresslist>");
$addressXML->addAttribute("resultcount",(int)self::get_resultcount());
$addressIndex = 0;
foreach ($addressArr as $addressObject) {
$addressNode = $addressXML->addChild("address");
$addressNode->addAttribute("id",(int)$addressIndex);
$addressNode->addChild("pickup",htmlspecialchars($addressObject->get_pickup()));
$addressNode->addChild("dropoff",htmlspecialchars($addressObject->get_dropoff()));
$addressNode->addChild("BookingDateTime",$addressObject->get_bookingtime());
$addressNode->addChild("Car",$addressObject->get_car());
$addressNode->addChild("JbMessage",$addressObject->get_status());
$addressNode->addChild("Zone",$addressObject->get_zone());
$addressNode->addChild("CustomerFare",$addressObject->get_fare());
$addressNode->addChild("PassName",$addressObject->get_passenger());
$addressNode->addChild("CarType",$addressObject->get_cartype());
$addressNode->addChild("Tel",$addressObject->get_tel());
$addressNode->addChild("Comments",$addressObject->get_comments());
$addressIndex += 1;
}
echo $addressXML->asXML();
}
输出: -
<addresslist resultcount="2">
<address id="0">
<pickup>ADDRESS 1</pickup>
<dropoff>ADDRESS 2</dropoff>
<bookingdatetime>16/04/2014 12:03:57</bookingdatetime>
<car></car>
<jbmessage></jbmessage>
<zone>NO ZONE</zone>
<customerfare>3.5</customerfare>
<passname>TEST</passname>
<cartype>CAR</cartype>
<tel>12345678912</tel>
<comments></comments>
</address>
</addresslist>
我需要做的是将其传递给jQuery文件,以便在jQGrid中显示信息。怎么可能实现这个目标?
答案 0 :(得分:0)
而不是XML使用JSON。它本身支持JavaScript,更小,更快。 要将PHP中的array / stdClass编码为JSON,您可以使用json_encode