Sunday, 19 April 2015

Parse xml in jquery - ajax



This code works.



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


This don't:



success: function( xml ) {

// Extract relevant data from XML
var xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "Country" );

console.log($title.text());

}


My xml form:



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://ift.tt/1i1S36V' );

//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.';
}

?>


My XML is returning object maybe that's why I can't getting my country names. I tried a lot but nothing getting work. I am using a web serivce Link as a demo test.


No comments:

Post a Comment