Javascript ajax 代码在 ibm worklight 中不起作用?

Javascript ajax code is not working in ibm worklight?

我正在使用 IBM Worklight.I 创建混合应用程序使用以下代码使用 jQuery 从服务器获取 XML 数据。

<script type="text/javascript">

                 (function ($) {
            /**
             * Constructor method that sets up a CORS hack
             * and makes the ajax request
             */
            function _construct() {
                // jquery cors hack to enable cross-domain loading
                // see: https://github.com/Rob--W/cors-anywhere/
                $.ajaxPrefilter(function (options) {
                if (options.crossDomain && $.support.cors) {
                    options.url = 'https://cors-anywhere.herokuapp.com/' + options.url;
                }
                });

                $.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) {
                    // this is the hack, it makes xml a breeze, simply 
                    // convert the xml data to a jquery object
                    var xmlJqueryObject = $(data);
                    render(xmlJqueryObject);
                }
                });

            }

            /**
             * Parses the xml then 
             */
            function render(feed) {
                var list = [];
                // we can use jquery selectors to pick the data
                // and choose the data we need


                feed.find('feed').each(function (i, item) {             

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

            //call the constructor
            _construct();

               })(jQuery);

</script>

它在浏览器 side.But 中获取并显示数据,同时将应用程序转换为 iOS 和 运行 作为 xcode 项目它显示以下错误。(获取数据时出错.) 如何解决它(或)解决它的任何其他替代解决方案。

适配器使您可以灵活地连接到任何后端系统类型。如果需要,您还可以利用 Worklight 的安全框架来保护对这些后端系统的访问。

对于您的问题,适配器还提供了一种方法,可以在后端响应返回到最初发送数据请求的客户端应用程序之前,对来自后端的响应使用 XSL 转换。

你可以read more关于它: