Last active
July 15, 2016 19:00
-
-
Save shrutis22/a8bd5817390eac46ef64d0652fafffa2 to your computer and use it in GitHub Desktop.
Javascript file created to parse the XML Response Body
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* [1] Will be fired when the Apex | |
* Method completes execution. | |
* | |
* [2] Will also hold the data returned | |
* by the Apex Method after it | |
* completes execution. | |
*/ | |
var searchTerm; | |
var newsFetchCompleted = function( res ) { | |
var parser = new DOMParser(); | |
var xmlDoc = parser.parseFromString( res, "text/xml" ); | |
var descriptions = xmlDoc.getElementsByTagName( "description" ); | |
for( var i = 0 ; i <= descriptions.length - 1 ; i++ ) { | |
if( descriptions[i].textContent !== "Google News" ) { | |
$( "#news" ).append( descriptions[i].textContent ); | |
$( "a" ).attr( "target" , "_blank" ); | |
} | |
} | |
$( "#loader" ).hide(); | |
}; | |
function getNews( searchTerm ) { | |
NewsWidgetController.newsDisplayer( searchTerm, | |
newsFetchCompleted, | |
{ | |
escape: false | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment