此代码有效。
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "title" );
console.log($title.text()); // RSS Title
这不是:
success: function( xml ) {
// Extract relevant data from XML
var xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "Country" );
console.log($title.text());
}
我的xml表单:
object(stdClass)[2]
public 'GetCitiesByCountryResult' => string '<NewDataSet>
<Table>
<Country>Spain</Country>
<City>Fuerteventura / Aeropuerto</City>
</Table>
<Table>
<Country>Spain</Country>
<City>Hierro / Aeropuerto</City>
</Table>
<Table>
<Country>Spain</Country>
<City>La Palma / Aeropuerto</City>
</Table>
<Table>
<Country>Spain</Country>
<City>Las Palmas De Gran Canaria / Gando</City>
</Table>
<Table>
<Country>Spain</Country>
<City>Lanzarote / Aeropuerto</City>
</Table>
<Table>
<Country>Spain</Country'... (length=4383)
PHP:
<?php
if ( isset( $_POST[ 'facultyname' ] ) ) {
//Create the client object
$soapclient = new SoapClient( 'http://www.webservicex.net/globalweather.asmx?WSDL' );
//Use the functions of the client, the params of the function are in the associative array.
$params = array( 'CountryName' => $_POST[ 'facultyname' ] );
$response = $soapclient->GetCitiesByCountry( $params );
var_dump( $response );
}
else {
echo 'Some error on php receiving side.';
}
?>
我的XML正在返回对象,也许这就是为什么我无法获取我的国家名称。我尝试了很多但没有工作。 我正在使用网络服务Link作为演示测试。