I am currently working on developing a hybrid app using IBM Worklight. In order to fetch XML data from the server, I have incorporated the following jQuery code.
<script type="text/javascript">
(function ($) {
/**
* Initialization of a CORS hack and execution of the ajax request
*/
function _construct() {
// jquery cors hack for cross-domain loading
$.ajaxPrefilter(function (options) {
if (options.crossDomain && $.support.cors) {
options.url = 'https://cors-anywhere.herokuapp.com/' + options.ur;
}
});
$.ajax({
type: 'GET',
datatype: 'xml',
crossDomain: true,
url: 'http://newsyogi.com/xml/india.xml',
error: function (textStatus, error) {
$('body').text('Error fetching feed :/');
},
success: function (data) {
var xmlJqueryObject = $(data);
render(xmlJqueryObject);
}
});
}
/**
* Parsing the XML data
*/
function render(feed) {
var list = [];
feed.find('feed').each(function () {
var $book = $(this);
var title = $book.find('title').text();
var description = $book.find('description').text();
var imageurl = $book.find('sort').text();
var dateTime= $book.find('news').text();
if (imageurl == "" ) {
imageurl='<img title="Be Transparent While Dealing With US: Congress to Government" alt="Be Transparent While Dealing With US: Congress to Government" id="story_image_main" src="http://www.ndtv.com/news/images/story_page/US_President_Obama_with_PM_Modi_White_House_650.jpg">';
}
$("#newsContent_area").append(
'<div class="col-xs-6 col-sm-4 col-md-4 col-lg-3 thumb "><div class="panel panel-default flex-col""><div class="panel-heading"> <div class="image_categories"> <h4 class="news-title">'+title+'</h4><img class="news_images img-responsive" src="'
+ imageurl +'"</div></div> </div><div class="panel-body flex-grow newscontent"><div class="news_caption"> <span class="news_categories "><a>'+description+'</a></span></div></div></div></div>');
});
}
//calling the constructor function
_construct();
})(jQuery);
</script>
While this implementation successfully retrieves and displays data on the browser side, there is an issue that arises when converting the app to iOS and running it as an Xcode project which results in the error message: "Error fetching data". Any suggestions on how to resolve this issue or alternative solutions would be greatly appreciated.