Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript ajax代码在ibm worklight中不工作?_Javascript_Ajax_Ibm Mobilefirst - Fatal编程技术网

Javascript ajax代码在ibm worklight中不工作?

Javascript ajax代码在ibm worklight中不工作?,javascript,ajax,ibm-mobilefirst,Javascript,Ajax,Ibm Mobilefirst,我正在使用IBM Worklight创建一个混合应用程序 <script type="text/javascript"> (function ($) { /** * Constructor method that sets up a CORS hack * and makes the ajax request */ func

我正在使用IBM Worklight创建一个混合应用程序

<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>

(函数($){
/**
*用于设置CORS hack的构造函数方法
*并发出ajax请求
*/
函数_构造(){
//jquery cors hack支持跨域加载
//见:https://github.com/Rob--W/cors-anywhere/
$.ajaxPrefilter(函数(选项){
if(options.crossDomain&&$.support.cors){
options.url=https://cors-anywhere.herokuapp.com/“+options.url;
}
});
$.ajax({
键入:“GET”,
数据类型:“xml”,
跨域:是的,
网址:'http://newsyogi.com/xml/india.xml',
错误:函数(文本状态,错误){
$('body').text('获取提要时出错:/');
},
成功:功能(数据){
//这就是黑客,它让xml变得轻而易举
//将xml数据转换为jquery对象
var xmlJqueryObject=$(数据);
呈现(xmlJqueryObject);
}
});
}
/**
*然后解析xml
*/
函数渲染(提要){
var列表=[];
//我们可以使用jquery选择器来选择数据
//选择我们需要的数据
feed.find('feed')。每个(函数(i,项){
//似乎很熟悉。。。
var$book=$(本);
var title=$book.find('title').text();
var description=$book.find('description').text();
var imageurl=$book.find('sort').text();
var dateTime=$book.find('news').text();
如果(imageurl==“”){
imageurl='';
}
$(“#新闻内容区”)。追加(

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

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

你可以:


您没有显示在Xcode控制台中遇到的错误。一种解决方案是:改用Worklight adapters。@IdanAdar Xcode在控制台中没有显示任何错误。它只显示加载相应的.html文件。使用Worklight adapters是解析xml数据(或)的唯一方法是否有其他方法来解析来自服务器的XML数据。适配器还允许您在结果数据到达客户端之前对其使用XSL转换。